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.
| Author |
Topic |
|
jas2005
Starting Member
11 Posts |
Posted - 2005-02-15 : 03:27:22
|
Dear All,I have a dynamic query as shown below[ Sample Code ]declare @strKey1 varchar(30), @strKey2 varchar(30), @mysql varchar(200)set @strKey1 = '[Type]'set @strKey2 = 'business'set @mysql = 'select title_id, type, pub_id from titles Where ' + @strKey1 + '=' + @strKey2Print @mysqlexec (@mysql)How do i make this code workable ???PLease advise / HELP !!! Thanks~j~A~s |
|
|
AndyB13
Aged Yak Warrior
583 Posts |
Posted - 2005-02-15 : 03:32:55
|
You need to enclose you variable @strKey2 in ''When you use PRINT, copy the text from the results and paste into the QA window and see if what you are generating worksWhere ' + @strKey1 + '=' + '''' + @strKey2 + ''''AndyBeauty is in the eyes of the beerholder |
 |
|
|
jas2005
Starting Member
11 Posts |
Posted - 2005-02-15 : 03:43:57
|
| Thanks...Andy :D~j~A~s |
 |
|
|
|
|
|