• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

MS SQL Error

Participant ,
Jun 02, 2012 Jun 02, 2012

Copy link to clipboard

Copied

I have inherited a project.  The orginal code was written when MX was around and the client was using 17 access db's to run the site.

I have converted the db's to MS SQL.

The following was the original query:

<CFQUERY NAME="GetPremium" datasource="#APPLICATION.DB#" USERNAME="#APPLICATION.UN#" PASSWORD="#APPLICATION.PW#" BLOCKFACTOR="100">

SELECT IIf(InStr([City],',') > 0, Left([City],InStr([City],',')-1), IIf(InStr([City],'&') > 0, Left([City], InStr([City],'&')-1), [City])) AS xCity, Count(Featured.ID) AS CountOfID

FROM Features INNER JOIN Featured ON Features.ID = Featured.ID

WHERE (((Featured.Type)='Facility') and ((Features.Cat)=<CFQUERYPARAM CFSQLTYPE="CF_SQL_CHAR" VALUE="#URL.Cat#">) and ((Featured.State)=<CFQUERYPARAM CFSQLTYPE="CF_SQL_CHAR" VALUE="#URL.ST#">) )

GROUP BY IIf(InStr([City],',') > 0, Left([City], InStr([City],',')-1) ,IIf(InStr([City],'&') > 0, Left([City],InStr([City],'&')-1), [City]))

</CFQUERY>

I changed it to:

<CFQUERY NAME="GetPremium" datasource="#APPLICATION.DB#" USERNAME="#APPLICATION.UN#" PASSWORD="#APPLICATION.PW#" BLOCKFACTOR="100">

SELECT IIf(CHARINDEX([City],',') > 0, Left([City],CHARINDEX([City],',')-1), IIf(CHARINDEX([City],'&') > 0, Left([City], CHARINDEX([City],'&')-1), [City])) AS xCity, Count(Featured.ID) AS CountOfID

FROM Features INNER JOIN Featured ON Features.ID = Featured.ID

WHERE (((Featured.Type)='Facility') and ((Features.Cat)=<CFQUERYPARAM CFSQLTYPE="CF_SQL_CHAR" VALUE="#URL.Cat#">) and ((Featured.State)=<CFQUERYPARAM CFSQLTYPE="CF_SQL_CHAR" VALUE="#URL.ST#">) )

GROUP BY IIf(CHARINDEX([City],',') > 0, Left([City], CHARINDEX([City],',')-1) ,IIf(CHARINDEX([City],'&') > 0, Left([City],CHARINDEX([City],'&')-1), [City]))

</CFQUERY>

I know the InStr function does not work with MS SQL so I changed that to CHARINDEX.  Not sure if the formatting of the query needs to change or not or if I am any where close.

I am getting an MS SQL error stating: [SQLServer]Incorrect syntax near '>'.

Any suggestions would be helpful.

AJ


Views

800

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 02, 2012 Jun 02, 2012

Copy link to clipboard

Copied

I don't suppose iif() is an MS SQL function. Check it out.

Please also explain, in words, the following logic (I don't get it):

IIf(CHARINDEX([City],',') > 0, Left([City],CHARINDEX([City],',')-1), IIf(CHARINDEX([City],'&') > 0, Left([City], CHARINDEX([City],'&')-1), [City])) AS xCity

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jun 02, 2012 Jun 02, 2012

Copy link to clipboard

Copied

LATEST

I do not think MS SQL supports IIF. Try the more elegant CASE

http://msdn.microsoft.com/en-us/library/ms181765.aspx

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation