Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

SQL 2008 T-SQL Expand / Collapse
Author
Message
Posted Monday, August 24, 2009 8:36 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 10:58 AM
Points: 5,333, Visits: 25,272
Comments posted to this topic are about the item SQL 2008 T-SQL

If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Post #776407
Posted Tuesday, August 25, 2009 6:55 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Tuesday, October 7, 2014 12:42 PM
Points: 413, Visits: 310
Ummm.... I had an error when processing this sql. That is the option I picked before I answered and decided to check it after I was wrong.
Post #776621
Posted Tuesday, August 25, 2009 7:42 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Wednesday, October 15, 2014 12:04 PM
Points: 819, Visits: 1,657
did you try it in SSMS 2008? doens't work in 2005, those features are part of the 2008 version.
Post #776678
Posted Tuesday, August 25, 2009 7:45 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Tuesday, October 7, 2014 12:42 PM
Points: 413, Visits: 310
Did not. Thanks for the post.
Post #776684
Posted Tuesday, August 25, 2009 8:05 AM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Monday, September 29, 2014 11:11 AM
Points: 658, Visits: 401
I thought @msg *= 3 would not work -- my bad .
Post #776712
Posted Tuesday, August 25, 2009 9:15 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Thursday, September 25, 2014 2:58 PM
Points: 3,173, Visits: 1,267
I thought this wouldn't work because I assumed 2005 worked the same as 2008. I was surprised to see that I was wrong. I wanted to see it work in 2008 but when I ran it my server returned this error.

@i @Msg Date
----------- ----- --------
An error occurred while executing batch. Error message is: Invalid attempt to GetBytes on column 'Date'. The GetBytes function can only be used on columns of type Text, NText, or Image.

What does this mean?

-Kevin



Post #776782
Posted Tuesday, August 25, 2009 10:12 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, October 15, 2013 5:16 AM
Points: 147, Visits: 104
DECLARE @i AS INT = 100,@msg AS VARCHAR(5)= '11',@Date AS DATE=GETDATE()

will generate error "Cannot assign a default value to a local variable."


Bhavesh
.NET and SQL Server Blog
Post #776867
Posted Tuesday, August 25, 2009 10:46 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Thursday, September 25, 2014 2:58 PM
Points: 3,173, Visits: 1,267
bhavster27 (8/25/2009)
DECLARE @i AS INT = 100,@msg AS VARCHAR(5)= '11',@Date AS DATE=GETDATE()

will generate error "Cannot assign a default value to a local variable."


Not for SQL 2008



Post #776892
Posted Tuesday, August 25, 2009 10:55 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Tuesday, December 7, 2010 12:55 AM
Points: 771, Visits: 504
Good question!
Post #776897
Posted Tuesday, August 25, 2009 11:40 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, October 9, 2014 2:24 PM
Points: 367, Visits: 1,077
On my SQL 2008 server (using the Master database so no question of compatibility level) this fails with the previously mentioneed "GetBytes function" error.

use master
DECLARE @Date AS DATE=GETDATE()
SELECT @Date as '@Date'

An error occurred while executing batch. Error message is: Invalid attempt to GetBytes on column '@Date'. The GetBytes function can only be used on columns of type Text, NText, or Image.

If you explicitly cast the DATE to CHAR or VARCHAR then it works (also if you change the type of date to DATETIME). I'm not sure why this is so, as the conversion page says that there is an implicit conversion from Date to char and varchar AND no conversion possible to Text, NText or Image.

So, I got the right answer for the wrong reason, but it was graded wrong for an unknown reason. Sounds fair to me.
Post #776918
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse