question

JAKELIEW avatar image
JAKELIEW asked

Combine Print by SQL with different datatype

Here is my SQL from ms-access: SELECT WSID, StartDate +' ' + StartTime + ' '+ Duration, + ' ' + Descp as WSP, TID FROM Workshop I'm trying to print out expected result like this: 11/2/2016 1200 90 WORKSHOP 2 but since the datatype of startdate is date/time, StartTime is shorttext and duration is shorttext. Once i execute the SQL it get result like this: ![alt text][1] [1]: /storage/temp/3781-123213.png
sql queryaccess
123213.png (5.2 KiB)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
GPO avatar image
GPO answered
Your request (concatenating a date, a string for a time, and a duration (again as a string) into a single column, is rather unconventional. Two questions: 1. do you have any control over the database design (is it in it's infancy)? and 2. What are you going to do with the concatenated data? Taking your request at face value, I'd do this: SELECT WSID ,convert(varchar(8),StartDate,112) + ' ' + StartTime + ' ' + Duration as [Start date time] ,Descp as WSP ,TID FROM Workshop ...but I'm sure if we knew more about what you're trying to achieve, we could come up with something better. See [this][1] for more datetime formatting information. You can also use the new format() function in SQL Server 2012 and later to control the look of dates and times, but it's very slow over big datasets. [1]: https://msdn.microsoft.com/en-AU/library/ms187928.aspx
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.