April 29, 2010 at 10:39 am
I need to take a staff id 4 digit and return the value of 09XXXX. (XXXX being the staff Id's)
I tried to get the Staff id in one column and then the value of 09 in another column and would manipulate it in the spreadsheet but was told I cant do that...
Being a New Person to SQL I have banged my head for the last two days on this I think it can be done with the substring function or the case function but cant make it happen with either ...
Any help in the right direction would be awesome...
Thanks.
April 29, 2010 at 10:41 am
Roseane (4/29/2010)
I need to take a staff id 4 digit and return the value of 09XXXX. (XXXX being the staff Id's)I tried to get the Staff id in one column and then the value of 09 in another column and would manipulate it in the spreadsheet but was told I cant do that...
Being a New Person to SQL I have banged my head for the last two days on this I think it can be done with the substring function or the case function but cant make it happen with either ...
Any help in the right direction would be awesome...
Thanks.
if the column contains 09XXXX and u want to seperate XXXX, the simplest way to do is
select right(col1, 4) from table1
April 29, 2010 at 10:51 am
It sounds more like a concatenation problem rather than a substring.
select '09' + convert(varchar(4), id) from ....
will get you 09xxxx where xxxx is the id. If the id is already a char or varchar, you don't need the convert. If the id is NULL you may have to explicitly set the CONCAT_NULL_YIELDS_NULL option to get what you want.
April 29, 2010 at 10:52 am
The field Ther_id contains 1872 and I need the output to be 091872
April 29, 2010 at 11:08 am
So it's
select '09' + Ther_id
or
select '09' + convert(varchar(4),Ther_id)
depending on whether Ther_id is a character or numeric datatype already.
April 29, 2010 at 11:18 am
You are so my Hero David.... It works wonderful... Thank you.
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply