August 24, 2009 at 8:36 pm
Comments posted to this topic are about the item SQL 2008 T-SQL
August 25, 2009 at 6:55 am
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.
August 25, 2009 at 7:42 am
did you try it in SSMS 2008? doens't work in 2005, those features are part of the 2008 version.
August 25, 2009 at 7:45 am
Did not. Thanks for the post.
August 25, 2009 at 8:06 am
I thought [font="Courier New"]@msg *= 3[/font] would not work -- my bad :-).
August 25, 2009 at 9:15 am
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
August 25, 2009 at 10:12 am
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
August 25, 2009 at 10:46 am
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
August 25, 2009 at 10:55 am
Good question!
August 25, 2009 at 11:40 am
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.
August 25, 2009 at 12:36 pm
john.moreno (8/25/2009)
On my SQL 2008 server (using the Master database so no question of compatibility level) this fails with the previously mentioneed "GetBytes function" error.
I found that the reason I got the GetBytes error was because I was connecting to the SQL 2008 server with MSSMS 2005.
August 25, 2009 at 1:03 pm
kevin.l.williams (8/25/2009)
I found that the reason I got the GetBytes error was because I was connecting to the SQL 2008 server with MSSMS 2005.
I thought I was connected with the MSSMS 2008, but checking shows that you are right, I was using 2005.
August 25, 2009 at 10:18 pm
the statement below is same for sql server 2005
DECLARE @i AS INT
declare @msg AS VARCHAR(5)
declare @Date AS DATEtime
set @i =100;
set @msg ='11';
set @Date =GETDATE()
SET @i =@i +25;
SET @i =@i *10;
SET @i =@i / 1000;
SET @msg =@msg*3;
SELECT @i AS '@i', @msg AS '@Msg', @Date AS 'Date'
and will give same answer as in 2008....
@i @Msg Date
----------- ----- -----------------------
1 33 2009-08-26 09:45:49.150
August 25, 2009 at 10:24 pm
the statement below is same for sql server 2005
DECLARE @i AS INT
declare @msg AS VARCHAR(5)
declare @Date AS DATEtime
set @i =100;
set @msg ='11';
set @Date =GETDATE()
SET @i =@i +25;
SET @i =@i *10;
SET @i =@i / 1000;
SET @msg =@msg*3;
SELECT @i AS '@i', @msg AS '@Msg', @Date AS 'Date'
and will give same answer as in 2008....
@i @Msg Date
----------- ----- -----------------------
1 33 2009-08-26 09:45:49.150
August 25, 2009 at 10:26 pm
the statement below is same for sql server 2005
DECLARE @i AS INT
declare @msg AS VARCHAR(5)
declare @Date AS DATEtime
set @i =100;
set @msg ='11';
set @Date =GETDATE()
SET @i =@i +25;
SET @i =@i *10;
SET @i =@i / 1000;
SET @msg =@msg*3;
SELECT @i AS '@i', @msg AS '@Msg', @Date AS 'Date'
and will give same answer as in 2008....
@i @Msg Date
----------- ----- -----------------------
1 33 2009-08-26 09:45:49.150
Viewing 15 posts - 1 through 15 (of 23 total)
You must be logged in to reply to this topic. Login to reply