Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with splitting date & time

Author  Topic 

stylishjm
Starting Member

17 Posts

Posted - 2012-09-28 : 07:24:10
Hello,

I have the following code in a batch file that runs every night. It exports restaurant speed of service times.

sqlcmd -S SERVER\01 -d Office -E -Q "SELECT DISTINCT QsrUser.SpeedOfService.Timestamp,QsrUser.SpeedOfService.VirtualDisplayName,QsrUser.SpeedOfService.LastBumpTime,QsrUser.SpeedOfService.FirstDisplayedTime,QsrUser.SpeedOfService.TransactionNumber FROM QsrUser.SpeedOfService WHERE Timestamp>= dateadd(day,-360,getdate()) order by Timestamp desc" -o "SpeedofService.csv" -h-1 -s"," -w 700


However, I require the date and time to be divided, rather than showing within one "column" as yymmdd hhmmss so that the CSV will display as yymmdd, hhmmss,

Is this possible?

Thank you
James

karthik0805
Starting Member

14 Posts

Posted - 2012-09-28 : 07:31:40
SELECT CONVERT(VARCHAR(50),'datetimecolumn',105),CONVERT(VARCHAR(50),'datetimecolumn',108)
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-09-28 : 07:47:18
[code]
sqlcmd -S SERVER\01 -d Office -E -Q
"SELECT DISTINCT CONVERT(VARCHAR(50),QsrUser.SpeedOfService.Timestamp,105) AS [Date],
CONVERT(VARCHAR(50),QsrUser.SpeedOfService.Timestamp,108) AS [Time],
QsrUser.SpeedOfService.VirtualDisplayName,
QsrUser.SpeedOfService.LastBumpTime,
QsrUser.SpeedOfService.FirstDisplayedTime,
QsrUser.SpeedOfService.TransactionNumber
FROM QsrUser.SpeedOfService WHERE Timestamp>= dateadd(day,-360,getdate())
order by [Date] desc, [Time] desc" -o "SpeedofService.csv" -h-1 -s"," -w 700
[/code]

--
Chandu
Go to Top of Page

stylishjm
Starting Member

17 Posts

Posted - 2012-09-28 : 08:01:28
Perfect that worked as wanted. Thanks Guys!
Go to Top of Page
   

- Advertisement -