ExpertKapur
asked on
Date Time and VARCHAR
Hi,
I have a variable like @OrderTime varchar(8) now this variable I am using to add a timestamp to a file. Like SET @FileName = 'xyz' + @OrderTime.+ '.xml'
My file should look like this xyz20101229130446470.xml . How Can I do that? I want everything except the millisecond part so 470 will be removed and it should be xyz20101229130446.xml
I have a variable like @OrderTime varchar(8) now this variable I am using to add a timestamp to a file. Like SET @FileName = 'xyz' + @OrderTime.+ '.xml'
My file should look like this xyz20101229130446470.xml . How Can I do that? I want everything except the millisecond part so 470 will be removed and it should be xyz20101229130446.xml
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try
select @OrderTime = replace(replace(replace(co nvert(varc har(19),ge tdate(),21 ),'-',''), ':',''),' ','')
select @OrderTime = replace(replace(replace(co
Actually this is better:
select FileName = 'xyz' + CONVERT(CHAR(10),@OrderTime, 23) + SUBSTRING(CONVERT(varchar, @OrderTime, 100), 13, 5)+ '.xml' from yourtable
Guys, I said "better" compared to the original code I posted; not to you guys code.
Just wanted to clarify to avoid confusion.
Just wanted to clarify to avoid confusion.
ASKER
Thanks!
Open in new window