December 19, 2008 at 10:32 am
trying to assign month values to variables:
example:
set @quart = (select DATEPART(Quarter ,Date)) from @nums where Date = convert(varchar(50),getdate(), 103))
but gettin the following error
Msg 242, Level 16, State 3, Line 33
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
December 19, 2008 at 1:03 pm
trying to assign month values to variables:
Yet in your DATEPART you are using "quarter". What is in the @Nums table variable?
This little bit of code does not return an error but how you want / need to use it is not clear to me.
DECLARE @quart AS INT
SET @quart = (DATEPART(qq,GETDATE()))
SELECT @quart
It returns an integer value of 4.
If you use mm in the DATEPART function it properly returns a integer value of 12.
Can you explain further and someone might be able to assist you in greater detail.
December 22, 2008 at 1:38 pm
Error Says, It cannot convert varchar to datetime because the date is trying to convert is overflowing... This usually happens when date is impossible, like Feb 30, Sep31 etc..
The only place where I see you are converting a varchar to datatype is
where Date = convert(varchar(50),getdate(), 103))
I am guessing Date is datetime datatype which you are comparing with a varchar datatype ( right side of where cluase )
to compare this you can do either one of below two ,
1. Convert Date column to varchar datatype
Ex: where convert(varchar(50) , Date , 103) = convert(varchar(50),getdate(), 103))
In this example both are varchars.
2. Convert right side of where clause to Datetime.
Ex: Where Date = convert (datetime, getdate(), style)
here style is the number which signifies the format of datetime stamp in Date column.
Regards
IM
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply