Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

parameter with dynamic query

$
0
0

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



Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>