Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 declare table

Author  Topic 

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2013-11-05 : 06:10:43
hi need to test info from a table to see if my query is wqorking right. trying to test a bit of a time. trying the below code first but keep getting Must declare the table variable "@WorkingNamingTable".
i have declared it so not sure why it wont work. any ideas anyone


-- Declare varibles 
DECLARE
@SQLStmt NVARCHAR(MAX),
@FieldName NVARCHAR(50),
@StringReplacement NVARCHAR(200),
@StringToFind NVARCHAR(200),
@maxPK INT,
@pk INT,
@Quote NVARCHAR(1),
@WorkingNamingTable NVARCHAR(256),
@WorkingDataloadFile2 NVARCHAR(256)
--@WorkingNamingTable = 'WorkingNamingTable'
--SELECT @WorkingDataloadFile2 = 'WorkingDataloadFile2'

SELECT @FieldName = Field from @WorkingNamingTable WHERE PK_ID = (Select PK_ID From #StringReplace Where PK_ID = @pk)

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2013-11-05 : 06:20:57
You need to use Dynamic SQL. But why are you doing this?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2013-11-05 : 06:23:59
i have a query that im using in ssis and im getting an error and i cant figure out why it wont work im just trying to figure out why it wont work. it should works for another person in a different package thats does the same thing but wont work for me
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-05 : 08:19:53
Wherever you use the above query wont work as its not syntactically correct.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -