Link to home
Start Free TrialLog in
Avatar of Paula DiTallo
Paula DiTalloFlag for United States of America

asked on

SQL Server 2005: Case Logic in Dynamic SQL

Hi Techies--

I am getting the error:

Incorrect syntax near the keyword 'as'.

...because I am trying to dub a column name within case/end logic.  Does anyone have a suggestion on how to solve this issue?

[begin snippet]

SET @Sql = N'
SELECT
 pat.AssemblyNum as ''assemblyNumber'',
 pat.PatternNum as ''patternNumber'',
 pat.Corner as ''cornerNumber'',
 class.PatClassTypeName as ''className'',
 case
  when pat.MatchTypeID = ''101'' then pat.Width/2 as ''repeatWidth''
  else pat.Width as ''repeatWidth''
 end ,
 pat.Length as ''repeatLength'',
 match.MatchTypeName as ''matchType'',
 pat.CollectionID as ''collectionID'',
 coll.CollectionName as ''collectionName''
FROM PatternClassType class, Collections coll, Patterns pat
    LEFT OUTER JOIN MatchType match
       ON pat.matchtypeid = match.matchtypeid

[end snippet]

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of BrandonGalderisi
BrandonGalderisi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Paula DiTallo

ASKER

brilliantly done!:-)