question

Peter.Eden avatar image
Peter.Eden asked

Error: Incorrect Syntax when adding constants

I am trying to add constants to a query to fill columns as I am doing a union all and one of the views I am querying doesn't have all the relevent columns. My code is thus: SELECT Date, Period, Code, NetAmount, Ref, Details, Site, TransRef, [Supp Code] AS Supplier, [Supplier Name] AS SupplierName, OurRef FROM dbo.vw_bsMET Union All SELECT Date, Period, Code, NetAmount, Ref, 'Details, Site, TransRef, [Supp Code], [Supplier Name], Ref2 AS OurRef FROM dbo.vw_plMET Union All SELECT Date, Period, 'Code' AS Code, NetAmount, 'Creditor' AS Ref, 'Creditors' AS Details, 'Site' AS Site, Ref AS TransRef, Supplier, SupplierName, InvRef AS OurRef FROM dbo.vw_SuppMET I get an error as follows: ![alt text][1] The Constants are in the third select ... 'Code' 'Creditor' 'Creditors' 'Site' I am not sure where I am going wrong ! [1]: /storage/temp/1762-sql1.jpg
syntax
sql1.jpg (27.9 KiB)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
David Wimbush avatar image
David Wimbush answered
Hi Peter. I don't think you need those single quotes at all so it doesn't really matter where it's going wrong. Just take them out and you should be fine.
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Peter.Eden avatar image Peter.Eden commented ·
Actually it was simpler than that. I had a rogue ' in the middle of teh second Select statement which is obvious in the pasted code above as it turns everything green i.e. a comment. I now just have to fix a collation error!
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.