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 |
casati74
Posting Yak Master
109 Posts |
Posted - 2006-09-07 : 09:31:57
|
It' s possible to write this if not exists (exec (@sql))where set @sql = ' select '+@ConditionField+' from '+@InvolvedTable+'where'+@ConditionField+'='+@ConditionValueI recive a error on exec |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-09-07 : 09:37:41
|
Well... If you received an error, I think it is not possible.Select the DYNAMIC SQL query into a temporary table and use EXISTS against the temporary table.Peter LarssonHelsingborg, Sweden |
|
|
casati74
Posting Yak Master
109 Posts |
Posted - 2006-09-07 : 09:49:04
|
For my it's ok this solution but I recive a error messagedeclare @ConditionField nvarchar(50), @ConditionValue nvarchar(50), @InvolvedTable nvarchar(50), @CondValue nvarchar(50)set @ConditionField = 'MaterialID'set @CondValue = '3'set @InvolvedTable = 'EAFAdditions'if exists (select @ConditionField, @ConditionValue from @InvolvedTable where @CondValue = 3)beginprint 'ciaio'endHe said me i must declare variable @InvolvedTable on from clausule; why????? |
|
|
eyechart
Master Smack Fu Yak Hacker
3575 Posts |
Posted - 2006-09-07 : 09:56:07
|
you can't use a variable in the FROM clause like this. You need to use dynamic sql if you want to pass an argument to your sproc (a table name for example) that is then used in a the FROM clause of a query.-ec |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2006-09-07 : 16:01:57
|
[code]if exists (select @ConditionField, @ConditionValue from @InvolvedTable where @CondValue = 3)beginprint 'ciao'end[/code]ciao!well put... |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-09-08 : 03:13:13
|
Priceless!Peter LarssonHelsingborg, Sweden |
|
|
|
|
|