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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Concatenate Fields withing SQL Select Clause

Status
Not open for further replies.

2Plan

MIS
Mar 29, 2005
55
US
How can I concatenate CommProjCode with UniqProjCode as FilePlanCode?

sql = "SELECT MasterProjectCodes.CommProjCode \& '-' \& CommonProjectCodes.UniqProjCode As FilePlanCode, " & _
" INTO Temp FROM CommonProjectCodes INNER JOIN MasterProjectCodes ON " & _
"CommonProjectCodes.CommProjCode = MasterProjectCodes.CommProjCode " & _
"WHERE MasterProjectCodes.FileCodeOwner Like " _
& "'" & Form.txtCodeSearch.Value & "'
 
SELECT MasterProjectCodes.CommProjCode & " & "-" & " & CommonProjectCodes.UniqProjCode As FilePlanCode, " & _
" INTO Temp FROM CommonProjectCodes INNER JOIN MasterProjectCodes ON " & _
"CommonProjectCodes.CommProjCode = MasterProjectCodes.CommProjCode " & _
"WHERE MasterProjectCodes.FileCodeOwner Like " _
& "'" & Form.txtCodeSearch.Value & "'"
 
Hello 2Plan!

I you're wanting the results of your query to be concatenated, use the double pipe ||.
Code:
sql = "SELECT COLUMN1 || '-' || COLUMN2 FROM TABLENAME"

Good luck!

He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
This works!

sql = "SELECT MasterProjectCodes.* " & _
" INTO Temp FROM CommonProjectCodes INNER JOIN MasterProjectCodes ON " & _
"CommonProjectCodes.CommProjCode = MasterProjectCodes.CommProjCode " & _
"WHERE MasterProjectCodes.FileCodeOwner Like " _
& "'" & Form.txtCodeSearch.Value & "*'"

But this does not work! I get missing operator in query expression

sql="SELECT MasterProjectCodes.CommProjCode & " & "-" & " & CommonProjectCodes.UniqProjCode As FileCodePlan " & _
" INTO Temp FROM CommonProjectCodes INNER JOIN MasterProjectCodes ON " & _
"CommonProjectCodes.CommProjCode = MasterProjectCodes.CommProjCode " & _
"WHERE MasterProjectCodes.FileCodeOwner Like " _
& "'" & Form.txtCodeSearch.Value & "*'"

sql = "SELECT MasterProjectCodes.CommProjCode || '-' || CommonProjectCodes.UniqProjCode As FileCodePlan " & _
" INTO Temp FROM CommonProjectCodes INNER JOIN MasterProjectCodes ON " & _
"CommonProjectCodes.CommProjCode = MasterProjectCodes.CommProjCode " & _
"WHERE MasterProjectCodes.FileCodeOwner Like " _
& "'" & Form.txtCodeSearch.Value & "*'"

Can you see the problem?
Thanks!
 
What about
Code:
"SELECT MasterProjectCodes.CommProjCode & '-' & CommonProjectCodes.UniqProjCode As FilePlanCode, "

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top