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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-01-07 : 08:51:11
|
| A sanjay writes "I want to build my query by concat strings ex:@sql1='Select * from tblemployees where 'If @empid <> '' @sql1=@sql1 & ' emplooyeeID=' @empidlike the above but I am unable to execute pls can anybodt show me by an example how to write an SP or suggest a good book. " |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-01-07 : 08:54:22
|
???exec(@sql1)or sp_executeSQL -- look it up in BOL.Go with the flow & have fun! Else fight the flow |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-01-08 : 03:59:23
|
Try this@sql1='Select * from tblemployees where 'If @empid <> '' @sql1=@sql1 & ' emplooyeeID= ' + @empidExec(@sql1) Madhivanan |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2005-01-08 : 06:06:34
|
| declare @sql varchar(4000)If @empid <> '' select @sql1 = coalesce(@sql1 + ' and ', '') + ' emplooyeeID = ' + @empidselect @sql = coalesce(' where ' + @sql, '')select @sql1='Select * from tblemployees' + @sqlExec(@sql1)==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|