[dba-SQLServer] Building Query on the fly

David Emerson newsgrps at dalyn.co.nz
Wed Jan 26 15:59:32 CST 2022


Thanks Borge.  That is exactly what I am looking for.

-----Original Message-----
From: dba-SQLServer
<dba-sqlserver-bounces+newsgrps=dalyn.co.nz at databaseadvisors.com> On Behalf
Of Borge Hansen
Sent: Thursday, 27 January 2022 9:01 am
To: Discussion concerning MS SQL Server <dba-sqlserver at databaseadvisors.com>
Subject: Re: [dba-SQLServer] Building Query on the fly

Hi David,
Have a look here for pointers:
https://stackoverflow.com/questions/3085756/passing-sql-stored-procedure-ent
irety-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
>
>
_______________________________________________
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