Hi,
Query 1: Simple query.
Query2: Dynamic query.
The string from where condition is different for different company as well as table. So, I created the dynamic query as an example below . I have the exception for company and 10 and else. I might not have the right syntax, so please help.
Thanks
Query 1
select * from mytbl
where order in ('ABCD', 'EFGH')
Query 2
declare @query nvarchar(max)
declare @comp nvarchar(3)
declare @string nvarchar(50)
if @comp = 10
set @string = 'ABCD', 'EFGH'
else
set @string ='IJKL', 'MNOP'
end
set @query = '
select * from mytbl
where order in '+@string+'
'
exec sp_executesql @query