Help Wanted Msaccess PIVOT-query --&> MS-SQL View/sp

Jan 18, 2006

Can someone help me parsing this ms-access PIVOT sql-statement to a
ms-sql-server sql-statement?
Many thanks in advance

TRANSFORM Count(KlantenStops.id) AS AantalVanid
SELECT KlantenStops.Uitvoerder, KlantenStops.Klant
FROM KlantenStops
GROUP BY KlantenStops.Uitvoerder, KlantenStops.Klant
PIVOT DatePart("m",leverdatum,1,0) In
("1","2","3","4","5","6","7","8","9","10","11","12");

View 3 Replies


ADVERTISEMENT

T-SQL (SS2K8) :: Pivot Query - Convert Data From Original Table To Reporting View

Apr 8, 2014

I want to convert the data from Original Table to Reporting View like below, I have tried but not get success yet.

Original Table:
================================================================
Id || Id1 || Id2 || MasterId || Obs ||Dec || Act || Status || InstanceId
================================================================
1 || 138 || 60 || 1 || Obs1 ||Dec1 || Act1 || 0|| 14
2 || 138 || 60 || 2 || Obs2 ||Dec2 || Act2 || 1|| 14
3 || 138 || 60 || 3 || Obs3 ||Dec3 || Act3 || 1|| 14
4 || 138 || 60 || 4 || Obs4 ||Dec4 || Act4 || 0|| 14
5 || 138 || 60 || 5 || Obs5 ||Dec5 || Act5 || 1|| 14

View For Reporting:

Row Header:
Id1 || Id2 || MasterId1 || Obs1 ||Desc1 ||Act1 ||StatusId1||MasterId ||Obs2 ||Desc2 ||Act2 ||StatusId2 ||MasterId3||Obs3 ||Desc3 ||Act3 ||StatusId3||MasterId4||Obs4||Desc4 ||Act4 ||StatusId4 ||MasterId5||Obs5 ||Desc5 ||Act5 ||StatusId5||InstanceId

Row Values:
138 || 60 || 1 || Obs1 ||Desc1 ||Act1 ||0 ||2 ||Obs2 ||Desc2||Act2 ||1 ||3 ||Obs3||Desc3 ||Act3 ||2 ||4||Obs4||Desc4 ||Act4 ||0 ||5 ||Obs5 ||Desc5 ||Act5 ||1 ||14

View 6 Replies View Related

MS SQL Server View Linked Into MSAccess Is Not Updateable Recordset

Jul 29, 2004

Hi All,
How can I link a view into MS Access from MS Sql Server, that I can update as a tabble.
Thanks
Laszlo

View 3 Replies View Related

Power Pivot :: Show Images In Power View With Power Query On Excel Desktop Version / Office 365

Aug 2, 2015

I am trying to show images in a product listing in power view.I work with an excel 2013 desktop version based on an office 365 pro account.I did the following steps:

import of an excel file with an article list via power query and loading the data to the data model import jpg images from a folder via power query, setting content as binary type and loading the data to the data modellinking both tables in power pivot--> manage via the image namesetting the table behavior for the images table under power pivot --> manage --> Advanced (e.g. Default Image: Content)opening power view and building article cards with article number and imageProblem: only a camera icon shows up in power view

Is there a solution with a desktop version?Can I use my Office 365 Pro account to make it work? How?Why is there no solution showing images in a pivot table?Link to Dropbox with power pivot files 

View 9 Replies View Related

Cannot See The Colums In The Design View Of Queries SQL 2000 And MSAccess 2000(adp)

Nov 21, 2006

Cannot see the Colums in the "design view" of Queries. All i see when i want to design a new query is *columns

This happens in only one database, in other databases using same server i can see the colums and can tick them to view then in the query.

In enterprise manager i see all the columns.

Using SQL 2000 and MSAccess 2000

View 1 Replies View Related

Question MSDE: Query Analyzer Vs MSAccess ADP

Oct 3, 2005

Hi all!

I have one UDF which take 5 params. When I run this UDF from Query Analyzer (select * from dbo.UDFname (param1, ..., param5)), it take 5 seconds, but when I run from ADP project (doble click), it take > 200 seconds. In both situations I obtain the same result (of course). I look at the connexion, seems ok (File -> Connexion; in .adp).

Can anybody tell me why are this differences? And how to surpass this ? I want to use the access .adp to make one front to run a MSDE db.

Thank's in advance :)

koci.

View 2 Replies View Related

Question MSDE: Query Analyzer Vs MSAccess ADP

Sep 30, 2005

Hi all!

I have one UDF which take 5 params. When I run this UDF from Query Analyzer, it take 5 seconds, but when I run from ADP project (doble click), it take > 200 seconds. I look at the connexion, but I don't see nothing to change (File -> Connexion; in .adp).

Can anybody tell me why?

Thank's in advance :)

koci.

View 1 Replies View Related

A Simple Update Query Using A Date - Conversion From Msaccess

Mar 21, 2005

I'm converting an ASP system from using msaccess to SQL Server as the db engine, and I'm stumped on the following query

update
timecard
set
TcdDate = #3/18/05#


TcdDate is defined as a date/time type

It will not run with the date bracketed by # signs, and when I take them out, 1/1/1900 is stored in the dbs. Is there a different symbol to bracket the date with or should I be using a function to convert the date?

View 4 Replies View Related

Msaccess To Mssql Server Query Parser/convertor

Jul 23, 2005

Hi all,is there any tool which is capable to convert query initially written formsaccess database to query for mssql server.I have tons of queries which contains iif, trim and similar functions whichshould be converted to case, ltrim(rtrim(, etc. etc.Does anyone know for tool which could do that automatically?Thanks in advance,Anabella

View 1 Replies View Related

Dyanmic PIVOT View

Sep 12, 2007

(sorry, I don't know how to make the copied tables 'look right' but spaces should --> tabs)
Branches Table
B_ID Branch
0 OLD
1 ADM
2 CL1
3 CL2
4 NEB
5 PTO
6 HOL
9 MKT
10 CL3
12 IOW
15 IND
16 PAP
18 SOU
19 NOR
Value Table (Pk = Vid, FK = Bid)
VID BID Emp_id Value
1 4 1 100
2 4 1 200
3 10 1 300
4 3 2 400
5 4 2 500
6 4 2 600

Desired Result View
(Pivot on On Emp_id sum the value column)
Emp_ID OLD ADM CL1 CL2 NEB PTO HOL MKT CL3 IOW IND PAP SOU NOR
1 0 0 0 0 300 0 0 0 0 0 300 0 0 0
2 0 0 0 400 1100 0 0 0 0 0 0 0 0 0

My current solution is to use a pivot query similar to the below (note: ..etc. used to simplify the discussion), It gets me close with the exception of presenting the null values as null rather than 0, I can make that work!
SELECT Emp_id,[0] AS OLD, [1] AS AD, [2] AS CL1, [3] AS CL2, [4] AS NEB ....etc)
FROM (SELECT Emp_id, value, B_id
FROM Branches) P PIVOT (sum(value) FOR B_idId IN ([0], [1], [2], [3], [4].."etc.")) AS pvt
"Take the data from the Branches table, sum up the values for a employee then present as a "pivoted" sql view with each branch in a column and nulls converted to 0"

Finally here is the problem/question.

I don't want to 'hard' code the branches (as the solution above does), they will change over time as branches are added and I want the query to reflect these changes. The problem, I don't know how to proceed from here, I have looked at using a SSAS solution, but that seems like too much for such a simple problem and in any case, I don't know how to integrate the SSAS cube into the current Ms Access 2000 solution (moving from Access backend data store to SQL server 2005).

Note: all the examples I have found in the BOL and forums, hard code the columns

I am frankly overwhelmed be the number of options available in SQL Server 2005, and still am trying to 'get my mind' around some of the concepts. I'm sure I don't know many of the options available, much more how to best implement them. The BOL, while good, have not really provided the enlightment I seek.

If I have to go to a CLR solution, could one provide some simple guidance,
Thanks.

Ed Warren.


View 8 Replies View Related

SQL Server 2012 :: Error In PIVOT Using CTE In VIEW?

Oct 23, 2014

I would like to have rows presented as columns. That's why I use the PIVOT function at the end.The resultset will be presented in Excel using an external connection to the view.

When I try to save the view I get the error

Msg 4104, Level 16, State 1, Procedure _TEST, Line 47

The multi-part identifier "vk.OppCode" could not be bound.

Code (restricting the columns that I actually have to the relevant columns only):

USE [DBTest]
GO
/****** Object: View [dbo].[_TEST] Script Date: 23-10-2014 17:24:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON

[code]....

View 1 Replies View Related

Power Pivot :: To Open Up Diagram View

Apr 21, 2015

I am trying to open Diagram View in PowerPivot, when I go to "View" tab in PowerPivot window, it only show two options, "Freeze" and "Column Width".

View 2 Replies View Related

Power Pivot :: How To Detect New View Column

Aug 24, 2015

Using PowerPivot I created a connection to a view on a SQL Server database. All fields imported correctly.A column has since been added to the view. How do I get this to appear in my PowerPivot?

View 3 Replies View Related

SQL 2012 :: How To Format Data In A Grid View (Pivot)

Oct 23, 2015

I am looking for a way to create a stored procedure that will show inventory availability. I would like to show the Inventory Name, The Date, and if the inventory is "checked out" using the ID name of the person who has the item.

For example it would look like this:

--------------------------------------------------------------------------------------------------
Inventory Name | 10/24/2015 | 10/25/2015 | 10/26/2015 | 10/27/2015 | 10/28/2015
--------------------------------------------------------------------------------------------------
Laptop | Tom | Tom | Tom | Avail | Avail
Projector | Avail | Avail | Avail | Avail | Bob
Air Card | Bob | Bob | Bob | Bob | Bob

It seems like I want to do a pivot table but there really is no aggregate so I am not sure what to use.

View 8 Replies View Related

Dynamic PIVOT Table As Data Source View

May 29, 2008

I would like to use a dynamic pivot table in my data source view. It seems that a named query can be only one sql statement. So, I cannot use my multi-statement procedure that creates a dynamic pivot table output.

What is the best course of action here? I could hard-code my pivot table query. I could maintain a redundant table in the pivot format. Do I have any good options?

KenS


Ken

View 1 Replies View Related

Power Pivot :: How To Get Back To Traditional Hierarchy Dimensional View

Jun 17, 2015

When ever I create a new Powerpivot from an AS cube, PowerPivot shows the data only in flattened PowerPivot format. How can I get back to traditional hierarchy dimensional view in Pivot table.

View 5 Replies View Related

SQL Server 2012 :: Creating A View Or Procedure From Dynamic Pivot Table

May 29, 2015

I have written a script to pivot a table into multiple columns.

The script works when run on its own but gives an error when i try to create a view or aprocedure from the same script. The temporary table #.... does not work so i have converted it to a cte.

Here is a copy of the script below

-- Dynamic PIVOT
IF OBJECT_ID('#External_Referrals') IS NULL
DROP TABLE #External_Referrals;
GO
DECLARE @T AS TABLE(y INT NOT NULL PRIMARY KEY);

[Code] ....

View 7 Replies View Related

Different Query Plans For View And View Definition Statement

Mar 9, 2006

I compared view query plan with query plan if I run the same statementfrom view definition and get different results. View plan is moreexpensive and runs longer. View contains 4 inner joins, statisticsupdated for all tables. Any ideas?

View 10 Replies View Related

Power Pivot :: Create Power View Report - Button Does Not Show Up For Some Reports

Nov 3, 2015

I have several reports in a Power View Gallery. In Gallery view, most of the reports show the "Open New Excel Workbook", the "Create Power View Report", and the "Manage Data Refresh" buttons on the right side of the report list. Why would some reports not have these buttons available? In the attached image you can see one report with the buttons and one without the buttons.

View 5 Replies View Related

Power Pivot :: Power View - Mix Series Types On Same Chart

Jul 25, 2015

I'm a relative newcomer to Power View. I've been playing with charts and have been struggling to combine both line and bar on the same chart. It would appear this functionality is not available. Considering this is basic functionality when it comes to charting, how to achieve this....

View 3 Replies View Related

Help With Pivot Crosstab Query (was Query Idea ??)

Feb 19, 2008

consider the following table:
name , TaskDate
john , 01/01/2006
john , 01/03/2005
steve , 01/05/2006
i want to build a select statement that gives result like the following:
name , JanuaryTotal , FebruaryTotal
john , 150 , 110
steve , 170 , 50
so the result will be total tasks in specific month, is it doable in one select or should i turn around using hash tables ???

View 6 Replies View Related

SQL Guru Wanted

Aug 2, 2006

Ok guys I have read everything in my previous post but unfortunately can not seem to get it to work properly. Would anyone like to do this 10 minutes work (I am sure). Obviously I dont expect it to be free but if I continue I am going to get a sledge hammer to this now.

Thanks in advance

View 20 Replies View Related

Query Help - Pivot

Mar 8, 2004

Hi, I have the following query that kinda does what i want

SELECT ABTANumber, TourOperator, ReportStatus,
COUNT(*) AS Counter
FROM (SELECT ABTANumber, TourOperator, r.ReportStatus FROM bookingdetails bd LEFT JOIN report r ON bd.Id = r.BookingDetailsId) a
GROUP BY ABTANumber, TourOperator, ReportStatus

This is what it displays

TourOp|ReportStatus|Count
JMC..... Fail.............. .10
JMC..... Pass..............621
JMC..... Warn.............5
SET..... Fail.............. .12
SET..... Pass..............621
SET..... Warn.............3

But what i want to display is this

TourOp|Pass|Fail|Warn
JMC......621 ..10....5
SET..... 621...12....3

I'm really stuck on this and would appreciate any help
thanks
Mark

View 2 Replies View Related

Help On Query Pivot...

Mar 30, 2006

hi,
I've table TAB_QUESTION:

ID_QUESTION..........VALUE_ID..........NUM_ANSWER. .....DESC_ANSWER
XB1.................1...................0......... .....YES
XB1.................2...................0......... .....NO
XB1.................3...................1......... .....GOOD
XB1.................4...................0......... .....SUFF
XB1.................5...................1......... .....NO_GOOD
XB1.................6...................0......... .....NR
XB1.................7...................0......... .....NN

YB1.................1...................1......... .....YES
YB1.................2...................2......... .....NO
YB1.................3...................3......... .....GOOD
YB1.................4...................0......... .....SUFF
YB1.................5...................3......... .....NO_GOOD
YB1.................6...................2......... .....NR
YB1.................7...................1......... .....NN

ZC1.................1...................0......... .....YES
ZC1.................2...................0......... .....NO
ZC1.................3...................0......... .....GOOD
ZC1.................4...................0......... .....SUFF
ZC1.................5...................0......... .....NO_GOOD
ZC1.................6...................0......... .....NR
ZC1.................7...................1......... .....NN

TC1.................1...................1......... .....YES
TC1.................2...................1......... .....NO
TC1.................3...................1......... .....GOOD
TC1.................4...................1......... .....SUFF
TC1.................5...................1......... .....NO_GOOD
TC1.................6...................0......... .....NR
TC1.................7...................0......... .....NN

.................................................. ........
.................................................. ........

I've always JUST 7 (seven) DESC_ANSWER (YES,NO,GOOD,SUFF,NO_GOOD,NR,NN)
Now I'd like to have ID_QUESTION like columns and DESC_ANSWER like rows.

like this:

DESC_ANSWER..........XB1........YB1............ZC1 ........TC1
YES.........................0..........1.......... ....0...........1
NO...........................0..........2......... .....0...........1
GOOD.......................1..........3........... ...0...........1
SUFF........................0..........0.......... ....0...........1
NO_GOOD..................1..........3............. .0...........1
NR...........................0..........2......... .....0...........0
NN...........................0..........1......... .....1...........0

How Can I write this query to get this output??

Thanks in advance!

View 2 Replies View Related

Pivot Query

Mar 24, 2008

SELECT
[R].[PaymentMonth],
[S].[RegionCode],
[S].[CmsStateShortName],
[P].[Attribute1] AS [FinalProduct],
[Membership] = SUM([R].[Membership])

FROM
[RptMMRSummary1] [R] INNER JOIN [RefCmsState1] [S]
ON [R].[CmsStateCode] = [S].[CmsStateCode]
INNER JOIN [RefPlanBenefitPackage1] [P]
ON [R].[PlanBenefitPackageID] = [P].[PlanBenefitPackageID]
WHERE
[R].[PaymentMonth] IN ('200712', '200711', '200612')
-- [P].[Attribute1] IN ('HMO', 'PPO', 'PFFS', 'SNP', 'EVCSNP')
GROUP BY
[R].[PaymentMonth],
[S].[RegionCode],
[S].[CmsStateShortName],
[P].[Attribute1]
-------------------------------------------------------------------
How do we use the pivot query for the above script. Layout as below

200801 Month / Year Selection

-------------------------------------------------------
StateShortname | Attribute | Attribute | Attribute | Total
----------------------------------------------------------
AL Values Values Values
OL Values Values Values
ZW Values Values Values
WEST Group By Region Code Total
BK Values Values Values
MN Values Values Values
EAST Group By Region Code Total

200712 Always Previous Month for the above selection Month /Year

-------------------------------------------------------
StateShortname | Attribute | Attribute | Attribute | Total
----------------------------------------------------------
AL Values Values Values
OL Values Values Values
ZW Values Values Values
WEST Group By Region Code Total
BK Values Values Values
MN Values Values Values
EAST Group By Region Code Total

200612 Always Previous year End Month for the above select Month / Year

-------------------------------------------------------
StateShortname | Attribute | Attribute | Attribute | Total
----------------------------------------------------------
AL Values Values Values
OL Values Values Values
ZW Values Values Values
WEST Group By Region Code Total
BK Values Values Values
MN Values Values Values
EAST Group By Region Code Total

Output :
[RegionCode],
[CmsStateShortName],
CurMonth_HMO, CurMonth_PPO, CurMonth_PFFS, CurMonth_SNP, CurMonth_EVCSNP,
PrevMonth_HMO, PrevMonth_PPO, PrevMonth_PFFS, PrevMonth_SNP, PrevMonth_EVCSNP,
PrevYrEndMonth_HMO, PrevYrEndMonth_PPO, PrevYrEndMonth_PFFS, PrevYrEndMonth_SNP, PrevYrEndMonth_EVCSNP

View 4 Replies View Related

Query On PIVOT

Dec 27, 2007

I€™ve a table with 2 columns with the following data

Col 1 Col2
---------------------------
Vista 2005
Distinguish 2005
ColonialVoice 2006
Vista 2006
Vista 2007
SuperiorCard 2007
Distinguish 2007

I would like to get the output in the following format using PIVOT function


2005 2006 2007
---------------------------------------------------------
Vista ColonialVoice Vista
Distinguish Vista SuperiorCard
Distinguish

Help me to write the query€¦

--
ash

View 3 Replies View Related

Query On PIVOT

Dec 27, 2007

I€™ve a table with 2 columns with the following data

Col 1 Col2
---------------------------
Vista 2005
Distinguish 2005
ColonialVoice 2006
Vista 2006
Vista 2007
SuperiorCard 2007
Distinguish 2007

I would like to get the output in the following format using PIVOT function


2005 2006 2007
---------------------------------------------------------
Vista ColonialVoice Vista
Distinguish Vista SuperiorCard
Distinguish

Help me to write the query€¦

--
ash

View 3 Replies View Related

Pivot Query

Sep 12, 2007


Hi,
I have a table EmpProject with following:
=========================
unitid projectid employees
----------- --------- -----------------------
1 CCT1 Ravi,Raja,Kanna
2 CCT1 John,Vijay,Nithya
1 CCT2 Senthil,Lee,Suresh
2 CCT2 Ram,Krish,Latha
2 CCT3 Raja,Vijay,Ram
2 CCT4 Sankar

TSql to create the above :
create table empproject (unitid int, projectid varchar(4), employees varchar(1000))
insert empproject select 1,'CCT1', 'Ravi,Raja,Kanna'
insert empproject select 2,'CCT1', 'John,Vijay,Nithya'
insert empproject select 1,'CCT2', 'Senthil,Lee,Suresh'
insert empproject select 2,'CCT2', 'Ram,Krish,Latha'
insert empproject select 2,'CCT3', 'Raja,Vijay,Ram'
insert empproject select 2,'CCT4', 'Sankar'


I would like to have it in the following format
========================================================
unitid CCT1 CCT2 CCT3 CCT4
----------------------------------------------------------------------------------------------------------------
1 Ravi,Raja,Kanna Senthil,Lee,Suresh
2 John,Vijay,Nithya Ram,Krish,Latha Raja,Vijay,Ram Sankar

Is there any way to query?

Thanks in Advance,


Nithyapriya

View 6 Replies View Related

Configuration Error...name Wanted

Nov 30, 2006

Hi, does somebody recognize the problem with my code? -Thanks!  
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. Parser Error Message: This is an unexpected token. The expected token is 'NAME'. Line 58, position 52.Source Error:  
<sessionState mode="SQLServer"stateConnectionString="Jensen"sqlConnectionString=
"datasource=Database;userid=username;password=pass"cookieless="false"timeout="60"/>

View 1 Replies View Related

SQL Developers In Seattle Wanted!

Sep 23, 1999

Always looking for people who are strong with microsoft technology for new oppurtunities in the Seattle area. If you are good, we can help you find your ideal next position.

don't be shy. shoot me an e-mail.

thanks

Pat Copeland

View 2 Replies View Related

SQL Developers In Seattle Wanted!

Sep 16, 1999

I am looking for strong SQL developers and/or DBA's for some really sweet companies here in Seattle. Anyone interested that is good and wants to hear about new oppurtunities? I would love to help you out.

don't be shy just shoot me an e-mail.

View 2 Replies View Related

VC++ Code Example For Extended SP - WANTED

May 8, 2002

Please help to find an example of the code written on VC++ for an extended stored procedure (dll) for SQL Server 2000.

Thanks

View 1 Replies View Related

Everything You Wanted To Know About Blocking...but Were Afraid To Ask

Mar 19, 2004

OK...this is driving me nuts....

In the First DELETE and bcp I was getting the thread being launched by xp_cmdshell was being blocked by the parent thread...

put in WAITFOR...sometime it worked...started with an empty table..it worked....left the 28k rows, blocked...

Now, put SELECT COUNT(*)...works each and every g-d damn time...

HUH?

Now I get to the bcp out..

added the same code WAITFOR/SELECT *...

blocks each and ever g-d damn time....

I'm very reticent to COMMIT and start another tranny block...

Anyone have any ideas?



SET NOCOUNT ON

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[wrk_DataHold]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[wrk_DataHold]
GO

CREATE TABLE wrk_DataHold(Col1 varchar(8000))
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[wrk_OldNew]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[wrk_OldNew]
GO

CREATE TABLE wrk_OldNew(Old varchar(255),New varchar(255))
GO


INSERT INTO wrk_OldNew(Old,New)
SELECT 'SEVERAL EE~S', ''
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_ModifyRows]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[usp_ModifyRows]
GO
CREATE PROC usp_ModifyRows
@Path sysname
, @FName sysname
AS

SET NOCOUNT ON

BEGIN TRAN

DECLARE @cmd varchar(8000), @Servername sysname, @rc int, @error int, @rowcount int
, @Old varchar(255), @New varchar(255), @x int

CREATE TABLE #bcpLog(Col1 varchar(8000))

SET @rc = 0

DELETE FROM wrk_DataHold

SELECT @error = @@error, @rowcount = @@ROWCOUNT
IF @error <> 0
BEGIN
SET @rc = -1
GOTO usp_ModifyRows_Error
END

SELECT @x=COUNT(*) FROM wrk_DataHold
WAITFOR DELAY '000:00:10'

SET @cmd = 'bcp wrk_DataHold in ' + @Path + @FName + ' -S ' + @@SERVERNAME + ' -U -P -c'
INSERT INTO #bcpLog(Col1) EXEC master..xp_cmdShell @cmd

DECLARE OldNew CURSOR FOR SELECT Old, New FROM wrk_OldNew

OPEN OldNew

FETCH NEXT FROM OldNew INTO @Old, @New

WHILE @@FETCH_STATUS = 0
BEGIN

UPDATE wrk_DataHold
SET Col1 = REPLACE(Col1,@Old,@New)
WHERE Col1 LIKE '%'+@Old+'%'

SELECT @error = @@error, @rowcount = @@ROWCOUNT
IF @error <> 0
BEGIN
SET @rc = -1
GOTO usp_ModifyRows_Error
END

INSERT INTO #bcpLog(Col1)
SELECT 'REPLACE "'+ RTRIM(@Old) + '" With "' + RTRIM(@New)+ '"' UNION ALL
SELECT '('+CONVERT(varchar(25),@rowcount)+' row(s) affected)'

FETCH NEXT FROM OldNew INTO @Old, @New
END

CLOSE OldNew
DEALLOCATE OldNew

SELECT @x=COUNT(*) FROM wrk_DataHold
WAITFOR DELAY '000:00:10'

SELECT @FName = SUBSTRING(@FName,1,CHARINDEX('.',@FName)-1)+'.new'

INSERT INTO #bcpLog(Col1)
SELECT 'Preparing to Write out new file '+ @Path + @FName
/*
SET @cmd = 'bcp wrk_DataHold out ' + @Path + @FName + ' -S ' + @@SERVERNAME + ' -U -P -c'
INSERT INTO #bcpLog(Col1) EXEC master..xp_cmdShell @cmd

SET @cmd = 'bcp #bcpLog out D:cpLog.txt -S ' + @@SERVERNAME + ' -U -P -c'
INSERT INTO #bcpLog(Col1) EXEC master..xp_cmdShell @cmd
*/

COMMIT TRAN

usp_ModifyRows_Exit:

SELECT * FROM #bcpLog
DROP TABLE #bcpLog
SET NOCOUNT OFF
RETURN @rc

usp_ModifyRows_Error:

CLOSE OldNew
DEALLOCATE OldNew
ROLLBACK TRAN
GOTO usp_ModifyRows_Exit

GO

SET NOCOUNT OFF

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved