Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Sql query help

Author  Topic 

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2011-12-12 : 14:52:53
I got the below error for the query

Conversion failed when converting date and/or time from character string.

Please help..


select SID AS SID_Reg,
ISNULL(CAST(SDATE AS DATETIME),NULL) AS SDATE_Reg,
SSTATE AS SSTATE_Reg,
St_status AS St_status_Reg,
(select B.Stud_FSCL_YR from stud_fiscyear B,Stu_data A WHERE B.Stud_FSCL_YR BETWEEN 2005 AND 2011
and ISNULL(CAST(A.SDATE AS DATETIME),NULL) IS NOT NULL
and ISNULL(CAST(A.SDATE AS DATETIME),NULL) BETWEEN B.STBGN_DT AND B.STEND_DT )AS ST_FSCL_YR,
(select B.STU_FSCLVL from stud_fiscyear B,Stu_data A
WHERE b.Stud_FSCL_YR BETWEEN 2008 AND 2011
and ISNULL(CAST(A.SDATE AS DATETIME),NULL) IS NOT NULL
and ISNULL(CAST(A.SDATE AS DATETIME),NULL) BETWEEN B.STBGN_DT AND B.STEND_DT )AS ST_FSCL_KVAL,
Rank() OVER (Partition by SID,SSTATE_Reg Order by ISNULL(CAST(SDATE AS DATETIME),NULL) asc) as 'Rank'
from Stu_data where St_status = 'Registered'

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2011-12-12 : 16:07:02
one of the rows in your query has SDATE value that is truly not a date. to find that row use ISDATE function. Why in the world a SDATE as anything but a datetime datatype?

If you don't have the passion to help people, you have no passion
Go to Top of Page

johntech
Yak Posting Veteran

51 Posts

Posted - 2011-12-14 : 08:25:06
Please could you give us the error message to help you
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-14 : 09:18:09
quote:
Originally posted by sqlfresher2k7

I got the below error for the query

Conversion failed when converting date and/or time from character string.

Please help..


select SID AS SID_Reg,
ISNULL(CAST(SDATE AS DATETIME),NULL) AS SDATE_Reg,
SSTATE AS SSTATE_Reg,
St_status AS St_status_Reg,
(select B.Stud_FSCL_YR from stud_fiscyear B,Stu_data A WHERE B.Stud_FSCL_YR BETWEEN 2005 AND 2011
and ISNULL(CAST(A.SDATE AS DATETIME),NULL) IS NOT NULL
and ISNULL(CAST(A.SDATE AS DATETIME),NULL) BETWEEN B.STBGN_DT AND B.STEND_DT )AS ST_FSCL_YR,
(select B.STU_FSCLVL from stud_fiscyear B,Stu_data A
WHERE b.Stud_FSCL_YR BETWEEN 2008 AND 2011
and ISNULL(CAST(A.SDATE AS DATETIME),NULL) IS NOT NULL
and ISNULL(CAST(A.SDATE AS DATETIME),NULL) BETWEEN B.STBGN_DT AND B.STEND_DT )AS ST_FSCL_KVAL,
Rank() OVER (Partition by SID,SSTATE_Reg Order by ISNULL(CAST(SDATE AS DATETIME),NULL) asc) as 'Rank'
from Stu_data where St_status = 'Registered'



see below for a probable reason

http://visakhm.blogspot.com/2011/12/why-iso-format-is-recommended-while.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -