[dba-SQLServer] Building Query on the fly

Borge Hansen pcs.accessd at gmail.com
Wed Jan 26 14:01:06 CST 2022


Hi David,
Have a look here for pointers:
https://stackoverflow.com/questions/3085756/passing-sql-stored-procedure-entirety-of-where-clause/3085815#3085815

/borge

On Thu, 27 Jan 2022 at 4:46 am, David Emerson <newsgrps at dalyn.co.nz> wrote:

> 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
>
>
>
>
> _______________________________________________
> dba-SQLServer mailing list
> dba-SQLServer at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/dba-sqlserver
> http://www.databaseadvisors.com
>
>


More information about the dba-SQLServer mailing list