Skip to Content
0

ORDER BY clause returning invalid column

Jan 03, 2017 at 02:34 PM

47

avatar image

Hi guys - I am almost embarrassed to come to the community with this one, but a relatively simple query has me baffled as to why adding an ORDER BY clause, breaks the query.

The following query works fine until I add the ORDER BY and then it states the T2.ItemCode column is invalid. It must be something to do with the WHERE clause but it has me stumped... it has had me stumped all morning and part of the afternoon.

Any help will of course, be greatfully appreciated:

SELECT T1.[DocNum]
, T1.[CardCode] AS 'Customer/Supplier No.'
, T1.[CardName] AS 'Customer/Supplier Name'
, T2.[ItemCode]
, T2.[Price] AS 'Price Quoted'
, T1.[CreateDate] AS 'Date Quoted'

FROM OQUT T1
INNER JOIN QUT1 T2 ON T2.DocEntry = T1.DocEntry

WHERE T2.[ItemCode] = [%0]

ORDER BY T2.ItemCode

Regards

Roy Bright

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
DIEGO LOTHER Jan 03, 2017 at 03:25 PM
0

Hi Roy,

The error occurs because the ItemCode field is a varchar field then you need put your parameter like this:

WHERE T2.[ItemCode] = '[%0]'

Your query should look like this:

SELECT 
	T1.[DocNum]
	, T1.[CardCode] AS 'Customer/Supplier No.'
	, T1.[CardName] AS 'Customer/Supplier Name'
	, T2.[ItemCode]
	, T2.[Price] AS 'Price Quoted'
	, T1.[CreateDate] AS 'Date Quoted'
FROM 
	OQUT T1
	INNER JOIN QUT1 T2 ON T2.DocEntry = T1.DocEntry
WHERE 
	T2.[ItemCode] = '[%0]'
ORDER BY 
	T2.ItemCode

Hope it helps.

Kind Regards,

Diego Lother

Share
10 |10000 characters needed characters left characters exceeded
Roy Bright Jan 03, 2017 at 03:54 PM
0

*slaps forehead* agggh - so simple - hahaha Thanks Diego, at this rate, I am gonna have to put you on the payroll hahaha

Regards

Roy

Show 1 Share
10 |10000 characters needed characters left characters exceeded

hahahhahahahah.

I stay happy to collaborate.

Have a nice day.

Kind Regards,

Diego Lother

1