Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid Column Name on Case Statement 1

Status
Not open for further replies.

LeonelSanchezJr

Programmer
Jan 26, 2001
522
US
I am getting an invalid column name on INLND_BL,
PO, HAWB, and POD. Any idea why?

Declare @SQL nVarChar(1024)
Set @SQL =
'Select
Hawb.cHawbNum
, Hawb.dShipDate
, Hawb.cOrigin
, Hawb.cDestin
, HawbDetail.cCustcode
, HawbDetail.dDueDate
, #TmpHawbsNoDoc.cDocType
From Hawb (nolock)
Join HawbDetail (nolock) on Hawb.cHawbNum = HawbDetail.cHawbNum
Join #TmpHawbsNoDoc On Hawb.cHawbNum = #TmpHawbsNoDoc.cHawbNum
Order By ' +
Case @cDocType
When Null Then 'cCustCode, cOrigin, dShipDate'
When "INLND_BL" Then 'cCustCode, cOrigin, dShipDate'
When "PO" Then 'cCustCode, cOrigin, dShipDate'
When "HAWB" Then 'cCustCode, cOrigin, dShipDate'
When "POD" Then 'cCustCode, cDestin, dShipDate'
End

Exec Sp_ExecuteSQL @SQL
 
You probably have quoted identifiers set ON. Add the following line at the front of your T-SQL script.

SET QUOTED_IDENTIFIER OFF Terry
------------------------------------
Experience is the hardest kind of teacher. It gives you the test first, and the lesson afterward.
 
Change the " to ' around the values in the When clause.

When 'INLND_BL' Then 'cCustCode, cOrigin, dShipDate'
Terry
------------------------------------
Experience is the hardest kind of teacher. It gives you the test first, and the lesson afterward.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top