April 5, 2010 at 3:55 pm
Hello and thanks ahead of time to all of your help.
I have a column that is an integer and it is hours and minutes here's example
1132
234
1
23
etc.
I want to add a zero to 234 to the left side and on 1 for instance I want to add a zero on the left and two on the right when it's ran so it will be 0234 so when i run it will be 02:34 and 01:00 respectively. Can someone point me in the right direction? Like do I need an if statement. I'm a little familar with Replicate but couldn't get it to work right.
April 5, 2010 at 4:10 pm
You will need to convert these to strings (varchar) in order to place a 0 in front of or behind an int.
To append or prepend the number with 0's, you will need to use a a conditional expression - case or if will work there.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
April 5, 2010 at 4:28 pm
if 234 is 02:34 then why on Earth would 1 be anything but 00:01???? :blink:
--Jeff Moden
Change is inevitable... Change for the better is not.
April 5, 2010 at 4:33 pm
Jeff Moden (4/5/2010)
if 234 is 02:34 then why on Earth would 1 be anything but 00:01???? :blink:
Nice catch there Jeff.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
April 5, 2010 at 4:37 pm
Why are you doing this? Is it for reporting or are you considering storing the data in this format?
April 5, 2010 at 5:31 pm
Steve Jones - Editor (4/5/2010)
Why are you doing this? Is it for reporting or are you considering storing the data in this format?
Heh... what the hey... Microsoft saw fit to do it (this mistake) in their job history logs and I'll just be that's where the data is being read from.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 5, 2010 at 8:37 pm
mosmits (4/5/2010)
Hello and thanks ahead of time to all of your help.I have a column that is an integer and it is hours and minutes here's example
1132
234
1
23
etc.
I want to add a zero to 234 to the left side and on 1 for instance I want to add a zero on the left and two on the right when it's ran so it will be 0234 so when i run it will be 02:34 and 01:00 respectively. Can someone point me in the right direction? Like do I need an if statement. I'm a little familar with Replicate but couldn't get it to work right.
Does the following code help you out?
create table #TestTable (
Col1 int
);
insert into #TestTable
select 1132 union all
select 234 union all
select 1 union all
select 23;
select
STUFF(RIGHT('00000000' + cast(Col1 as varchar(8)), 4),3,0,':')
from
#TestTable;
drop table #TestTable;
April 5, 2010 at 9:38 pm
CirquedeSQLeil (4/5/2010)
Jeff Moden (4/5/2010)
if 234 is 02:34 then why on Earth would 1 be anything but 00:01???? :blink:Nice catch there Jeff.
Heh... but still the OP has not replied on the matter. :hehe:
--Jeff Moden
Change is inevitable... Change for the better is not.
April 5, 2010 at 9:51 pm
Jeff Moden (4/5/2010)
CirquedeSQLeil (4/5/2010)
Jeff Moden (4/5/2010)
if 234 is 02:34 then why on Earth would 1 be anything but 00:01???? :blink:Nice catch there Jeff.
Heh... but still the OP has not replied on the matter. :hehe:
Maybe tomorrow 🙂
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
Viewing 9 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply