|
Comments
|
|
nice
|
|
|
nice
|
|
|
Excellent tutorial!!
|
|
|
Very good
|
|
Steve Harris on
3/11/2010
perhaps talk about other date functions like using CONVERT
|
|
|
Great vid
|
|
|
This is good general information, if the date you are recieving is in a format that is valid for the Datepart function..
However, I have a specific case, where I receive mmddyy, no punctuation. The following code:
SELECT
datepart(yyyy, '030510') as WhatYear
returns 2003 as the year, instead of 2010. In this case, I must parse the date.
|
|
|
A good introductory video. It would be nice to see a sample where the data format for a date column has changed in a table so users can see exactly what you mean when you say that "parsing out a year or month or quarter can be dangerous versus using the datepart function".
|
|
|
Awesome!
|
|
|
why use getutcdate and not getdate?
|
|
Sara Karasik on
3/11/2010
Really well presented, but way, way to simple and beginner level.
|
|
|
I know I need this one
|
|
|
I knew most of this but found the part about passing in a parameter value very helpful - I didn't know that piece. thank you very much - Denise
|
|
|
I always use the date formate dd-MMM-yyyy, as that always converts correctly. I created a function that always returns this date format, and I never have to worry about the culture of the box
|
|
|
Excellent video. Thanks.
|
|
|
Useful information but it didn't blow my mind...gave it a 3.
|
|
|
Keep these things coming!!!
|
|
|
I am new to sql right now, so this is beyond my skill set.
|
|
|
This is good stuff and very helpful. Thank you for sharing and keep up the good work.
|
|
|
Very helpful. I would be helpful if the examples could be downloaded.
|
|
|
It was a good video. I have a very slow connection, but it helped having the code written out, highlighted and executed. Thank you.
|
|
|
When the results pane will obscure the code in the query window, please scroll down so that the code remains in view as you get a results pane. This would help those of us who are a little slow or who cannot remember what we saw for a very brief time. Thanks. Andy, you do an outstanding job on these!! Diana Dee
|
|
|
Great series of videos - really appreciate the work you put into them. SO I don't want to appear 'picky', but your "prove it returns a string" example - uses DATEPART(), rather than DATENAME() - although the end result is the same ;-)
Additionally, probably too complex, but your last example could be achieved using Dynamic SQL.....
Like I said - love your work.
Andy
|
|
luther smith on
3/15/2010
Simple and clear.
|
|
|
I believe you have a mistake/oversight - you forgot to change "datepart" to "datename" in the "prove it returns a string" block.
What really matters is the datatype of your variable as these have identical results:
declare @YearInt int
declare @YearStr varchar(20)
select @YearInt = datename(yyyy,getutcdate())
select @YearStr = datename(yyyy,getutcdate())
select @YearInt, @YearStr
select @YearInt +10, @YearStr + 10
select @YearInt = datepart(yyyy,getutcdate())
select @YearStr = datepart(yyyy,getutcdate())
select @YearInt, @YearStr
select @YearInt +10, @YearStr + 10
|
|
|
getting the datepart back as on int---I've always done gross manipulated because I was changing it to a varchar
|
|
|
Well done. Very good point about maintaining integrity of values if inputted format of date data changes.
|
|
vin lawrence on
11/15/2010
excellent presentation very simple no nonsense apprach even though i already knew the subject matter
|
|
|
great job
|
|
|
declare @dnp nvarchar(5)
declare @dnSQL nvarchar(500)
declare @result nvarchar(25)
DECLARE @ParmDefinition nvarchar(500)
set @dnp = 'mm'
set @dnSQL = 'select @resultOut = DATEPART(' + @dnp + ',getutcdate())'
SET @ParmDefinition = N'@resultOut nvarchar(25) OUTPUT';
print @dnSQL
exec sp_executesql @dnSQL,@ParmDefinition, @resultOut = @result OUTPUT
select @result As Datepart
|
|
|
Great video, I have one question,
what is the difference of datepart with the functions day(), month() and year()?
|
|
|
thx.
|
|
|
did not know about the param not being valid - thanks for the heads up!
|
|
|
instead of the if's couldn't you use exec as:
declare @param varchar(4)
declare @cmd varchar(100)
select @param='yyyy'
select DATEPART(YYYY, GETDATE())
select @cmd = 'select datepart(' + @param + ', getdate())'
exec ( @cmd )
|
|
|
or you could also use the case statement such as:
declare @PartParam varchar (10)
SELECT @PartParam = 'mm'
SELECT case @PArtParam
when 'yyyy'
then datepart (yyyy, getutcdate())
when 'mm'
then datepart (mm, getutcdate()) end
|
|
Robert Banning on
12/17/2010
Great - simple - tip
|
|
Robert Banning on
12/17/2010
Great - simple - tip
|
|
Jamshid Nouri on
12/17/2010
Great demo
|
|
Lanny Mullis on
12/17/2010
What about using dynamic SQL in the last example?
|
|
|
very helpful!!
|
|
|
I've been wanting to know how to do that.
|
|
Tom Hamilton on
12/17/2010
excellent - thanks muc and Merry Christmas
|
|
|
good
|
|
|
simple fast and worthwhile on basic stuff
|
|
|
Sometimes you go too fast and there is not enough time to read your code before you run it. A simple solution would be to leave enough rows of white space below the query window content and scroll down so the code you are running remains visible above the query window. I know it would take more time in the presentation to do this, but it would be quite helpful to the listeners. Thanks again for a wonderful series! These videos are appreciated.
|
|
|
Regarding parameterized datename function, we can proceed this way also:
declare @part varchar(10)
set @part = 'mm'
declare @sql varchar(MAX)
set @sql = 'select datename('+@part+',getdate())'
print @sql
exec (@sql)
|