-
Dynamic sql with @sql
I have a where clause which I dynamically build that looks like this.
SET @orderstatus = ' (t.fieldvalue in ( ''PEND'', ''REDR'') or (t.fieldvalue=''NOTA'' and pr.isactive = 0)
or ((t.fieldvalue=''RXAP'' and m.formularymed = 0))
or (t.fieldvalue=''NOTA'' and pr.deano = @deano)) '
I then do @tsql = 'select * from table where ' + @orderstatus
The problem is I get the literal value @deano not the number that is stored in @deano
-
That's because you've enclised @deano inside single quotes. You need to concat @deano in the appropriate place
SET @orderstatus = ' (t.fieldvalue in ( ''PEND'', ''REDR'') or (t.fieldvalue=''NOTA'' and pr.isactive = 0)
or ((t.fieldvalue=''RXAP'' and m.formularymed = 0))
or (t.fieldvalue=''NOTA'' and pr.deano = ' + Cast(@deano as varchar) + ')) '
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|