tjpal
asked on
select statement with concatenation for three fields
Hi all,
Is there a way to select in vb.net kind of like the following:
select ID, fname, Year & Day & month from where foo = 5
I have this in a for loop
can it be done?
Is there a way to select in vb.net kind of like the following:
select ID, fname, Year & Day & month from where foo = 5
I have this in a for loop
can it be done?
SELECT ID, fname,TheDate=[Year] + [Day] + [Month]
FROM YourTableName
WHERE Foo='5'
FROM YourTableName
WHERE Foo='5'
What exactly are you trying to do ?
...if you post some code and explain a little what you are trying to accomplish I can probably help you better.
...if you post some code and explain a little what you are trying to accomplish I can probably help you better.
ASKER
I tried that, and thought it would work:
I tried:
SELECT ID, SR_ID, SR_Name, SR_Name_Show, SR_Address, SR_City, SR_State, SR_zip, SR_Phone, SR_Phone_Show, " & _
" SR_Fax, SR_Fax_Show, SR_Email, SR_JobID, SR_OpeningsID, SR_JobTitle, JobTypeCode, SR_SalaryRangeBase, SR_SalaryRangeHigh, " & _
" SR_LocName, SR_City1, SR_State1, SR_Zip1, SR_Date, SR_Job_Status,
JobBody=[SR_MCA_Other_Text ] + [PositionSummary] + [SR_PosReqs] from TheTable
close though
I tried:
SELECT ID, SR_ID, SR_Name, SR_Name_Show, SR_Address, SR_City, SR_State, SR_zip, SR_Phone, SR_Phone_Show, " & _
" SR_Fax, SR_Fax_Show, SR_Email, SR_JobID, SR_OpeningsID, SR_JobTitle, JobTypeCode, SR_SalaryRangeBase, SR_SalaryRangeHigh, " & _
" SR_LocName, SR_City1, SR_State1, SR_Zip1, SR_Date, SR_Job_Status,
JobBody=[SR_MCA_Other_Text
close though
Before concatinating numerical values, you need to convert them to character values.
select ID, fname, convert(varchar,[Year]) + convert(varchar,[Day])+convert(varchar,[month]) from table1 where foo = 5
As asked by xuserx2000, post your code. If your column is datetime/date datatype, you need not to extract year, month,day individually to get your required result.
try
SELECT ID, SR_ID, SR_Name, SR_Name_Show, SR_Address, SR_City, SR_State, SR_zip, SR_Phone, SR_Phone_Show, " & _
" SR_Fax, SR_Fax_Show, SR_Email, SR_JobID, SR_OpeningsID, SR_JobTitle, JobTypeCode, SR_SalaryRangeBase, SR_SalaryRangeHigh, " & _
" SR_LocName, SR_City1, SR_State1, SR_Zip1, SR_Date, SR_Job_Status, " & _
"[SR_MCA_Other_Text] + [PositionSummary] + [SR_PosReqs] JobBody " & _
from TheTable
ASKER
I figured some more of it. Here is what worked:
Cast(SR_MCA_Other_Text AS VARCHAR(5000)) +''+ CAST(PositionSummary AS VARCHAR(5000)) +''+ CAST(SR_PosReqs AS VARCHAR(5000)) AS JOBBODY
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
select ID, fname, Year + ' ' + Day + ' ' + month from where foo = 5
WHERE Foo='5'