Link to home
Start Free TrialLog in
Avatar of tjpal
tjpalFlag for United States of America

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?
Avatar of Ron Malmstead
Ron Malmstead
Flag of United States of America image

SELECT  ID, fname,TheDate=[Year] + [Day] + [Month]
WHERE Foo='5'
SELECT  ID, fname,TheDate=[Year] + [Day] + [Month]
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.
Avatar of tjpal

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
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

Open in new window

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

Open in new window

Avatar of tjpal

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
Avatar of Ephraim Wangoya
Ephraim Wangoya
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
select ID, fname, Year + ' ' + Day + ' ' + month from where foo = 5