Created
November 1, 2013 16:06
-
-
Save wellercs/7267631 to your computer and use it in GitHub Desktop.
Example of declaring and setting a SQL variable with cfqueryparam since there seems to be performance issues with large data sets when using cfqueryparam in a sub-select.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfset arguments.IsSold = 1> | |
<cfquery name="local.qryTraditional" datasource="cfartgallery"> | |
SELECT | |
a1.ArtistID | |
, a1.FirstName | |
, a1.LastName | |
, ( | |
SELECT TOP 1 LargeImage | |
FROM Art | |
WHERE IsSold = <cfqueryparam cfsqltype="cf_sql_bit" value="#arguments.IsSold#"> | |
) AS FirstSoldLargeImage | |
FROM Artists a1 | |
INNER JOIN Art a2 | |
ON a1.ArtistID = a2.ArtistID | |
WHERE 1 = 1 | |
</cfquery> | |
<cfquery name="local.qryWithSQLVar" datasource="cfartgallery"> | |
DECLARE @IsSold AS BIT | |
@IsSold = <cfqueryparam cfsqltype="cf_sql_bit" value="#arguments.IsSold#"> | |
SELECT | |
a1.ArtistID | |
, a1.FirstName | |
, a1.LastName | |
, ( | |
SELECT TOP 1 LargeImage | |
FROM Art | |
WHERE IsSold = @IsSold | |
) AS FirstSoldLargeImage | |
FROM Artists a1 | |
INNER JOIN Art a2 | |
ON a1.ArtistID = a2.ArtistID | |
WHERE 1 = 1 | |
</cfquery> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment