|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 9:02 PM
Points: 5,100,
Visits: 20,195
|
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 12:07 PM
Points: 353,
Visits: 287
|
|
| 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.
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: 2 days ago @ 1:53 PM
Points: 785,
Visits: 1,534
|
|
| did you try it in SSMS 2008? doens't work in 2005, those features are part of the 2008 version.
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 12:07 PM
Points: 353,
Visits: 287
|
|
| Did not. Thanks for the post.
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Thursday, January 17, 2013 2:34 PM
Points: 565,
Visits: 360
|
|
I thought @msg *= 3 would not work -- my bad .
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 8:29 AM
Points: 2,794,
Visits: 1,123
|
|
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
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, May 25, 2011 2:41 AM
Points: 145,
Visits: 99
|
|
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
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 8:29 AM
Points: 2,794,
Visits: 1,123
|
|
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
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Tuesday, December 07, 2010 12:55 AM
Points: 771,
Visits: 504
|
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 10:31 PM
Points: 339,
Visits: 950
|
|
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.
|
|
|
|