[dba-SQLServer] Building Query on the fly

David Emerson newsgrps at dalyn.co.nz
Wed Jan 26 12:45:57 CST 2022


Hi Listers,

I am wanting to build a query on the fly within a stored procedure and am
looking for pointers.

The final query will look something like this (very simplified - actual
query much more complex)

Insert into ttmpSite (tmpSiteName, tmpSiteRegion, tmpSiteType)
Select SiteName, SiteRegion, SiteType
>From tblSite
Where tblSite.SiteRegion IN ('East','West') AND tblSiteType IN (1,3)

The Where clause will be created from parameters passed into the procedure.

parSiteRegion - 'East','West'
parSiteType - 1,3

How should I structure the Where clause to use the par variables?

Regards

David Emerson
Dalyn Software Ltd
Wellington, New Zealand






More information about the dba-SQLServer mailing list