Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datetime to string 1

Status
Not open for further replies.

BlurredVision

Technical User
Aug 6, 2001
326
GB
Hello all,

Trying to create my first stored procedure and I am seeking a little help.

I need to combined two tables and thought a union would be best.

SELECT id, thru_date FROM Hospitals UNION SELECT id, FromDate FROM History;

My issue is, the thur_date is a string and the Fromdate is a datetime, how can I convert teh Fromdate to a string?

Thank you
 
Make thru_date also datetime :)
Also check CAST() and COVERT() functions in BOL.

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Ah..
SELECT id, CAST(WorkFromDate AS CHAR) FROM Work_History

Many thanks for the direction..
 
ALWAYS!!!! ALWAYS use length for the specific types (unless its not required).
N/VAR/CHAR, NUMERIC is one of these types. You never know when MS will change the default length of the type or if that length is equal for all versions of SQL Server.
So use CHAR(10), VARCHAR(200) or something but NOT just CHAR.

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
There was a blog on this exact topic on my favorite (now) site, but I could not find it in few minutes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top