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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL command question

Status
Not open for further replies.

DataOne

Programmer
Jan 12, 2011
10
US
What is the end result for this command?

SET @AGEDATE = '6/30/' + convert(varchar,YEAR('12/31/2010'))

Thanks
 
what is agedate declared as

Datetime or char,varchar
 
I saw many bad habits here:
1. Never use CONVERT or CAST functions w/o using the data length (when it is appropriate) and rely on the default lenght.
What if the next version of SQL Server changes it?
2. Always try to use so called ISO standard for dates (YYYYMMDD).
That way you are always independent from the SET DATEFORMAT.
What if you use this:
Code:
SET @AGEDATE = '11/12/2011'
What is this?
12 Nov 2011 or 11 Dec 2011?
Remember your application and database will not always be placed on American servers, and they may have different collations and dateformat.

The direct answer to your question:

Check PWise question :)




Borislav Borissov
VFP9 SP2, SQL Server 2000,2005 & 2008.
 
Datetime

I started with a new company and my ssms has not been installed yet.

Thanks
 
O, BTW this:
Code:
convert(varchar,YEAR('12/31/2010'))
is redundant for me.
You KNOW the year
convert(varchar,YEAR('12/31/2010'))
WHY you need to convert first to datetime and then to varchar

This is enough:
Code:
SET @AGEDATE = '6/30/2010'
or to be more in touch with my previous post:
Code:
SET @AGEDATE = '20100630'



Borislav Borissov
VFP9 SP2, SQL Server 2000,2005 & 2008.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top