SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


T-SQL


T-SQL

Author
Message
Gopi S
Gopi S
Old Hand
Old Hand (307 reputation)Old Hand (307 reputation)Old Hand (307 reputation)Old Hand (307 reputation)Old Hand (307 reputation)Old Hand (307 reputation)Old Hand (307 reputation)Old Hand (307 reputation)

Group: General Forum Members
Points: 307 Visits: 325
Comments posted to this topic are about the item T-SQL
UMG Developer
UMG Developer
SSCarpal Tunnel
SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

Group: General Forum Members
Points: 4082 Visits: 2204
Interesting question, thanks, and a good reason you should always specify the data type for hardcoded items when using a Table Value Constructor or UNION since data type precedence comes into play.

Here is a link to the Table Value Constructor in BOL that mentions the data type precedence: http://msdn.microsoft.com/en-us/library/dd776382.aspx, and here is a link for data type precedence: http://msdn.microsoft.com/en-us/library/ms190309.aspx

Edited to correct the information. (thanks Bradley!)
pksutha
pksutha
Valued Member
Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)

Group: General Forum Members
Points: 67 Visits: 58
No. My answer is first time BEGH, second time BEGH and Third time BEGH. Bcoz these two variables are varchar only. so if u pass the interger value without single quote it will accept.

First time :

insert into #test values
('1','A'),
('','B')
insert into #test values
(2,'D'),
('','E')
insert into #test values
('','G'),
('','H')
go
-- First select statement
select * from #test where c1 = ' '
delete #test
answer :
B
E
G
H

Second time:
insert into #test values
('1','A'),
('','B')
insert into #test values
('2','D'),
('','E')
insert into #test values
('','G'),
('','H')
go
-- Second select statement
select * from #test where c1 = ' '
delete #test

Third Time:

insert into #test values
(1,'A'),
('','B')
insert into #test values
(2,'D'),
('','E')
insert into #test values
('','G'),
('','H')
go
-- Third select statement
select * from #test where c1 = ' '

answer :
B
E
G
H


Note: So all three times the value comes same value only in SQLSERVER 2005
Gopi S
Gopi S
Old Hand
Old Hand (307 reputation)Old Hand (307 reputation)Old Hand (307 reputation)Old Hand (307 reputation)Old Hand (307 reputation)Old Hand (307 reputation)Old Hand (307 reputation)Old Hand (307 reputation)

Group: General Forum Members
Points: 307 Visits: 325
The question is " What is the output of the select statement from the below code
executed in sql server 10.0.1600 and with default settings " and not in SQL Server 2005 :-)

And are you sure this below code executed successfully in 2005 ?
insert into #test values
('1','A'),
('','B')


Thanks
tejaswini.patil
tejaswini.patil
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1168 Visits: 234
Gopinath Srirangan (3/22/2011)
The question is " What is the output of the select statement from the below code
executed in sql server 10.0.1600 and with default settings " and not in SQL Server 2005 :-)

And are you sure this below code executed successfully in 2005 ?
insert into #test values
('1','A'),
('','B')


Thanks


The Insert statement would definitely not work in 2005. The feature of inserting multiple rows using VALUE caluse is introduced in 2008.
tejaswini.patil
tejaswini.patil
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1168 Visits: 234
Interesting question.

Good learning for me.

Thanks.
tejaswini.patil
tejaswini.patil
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1168 Visits: 234
tejaswini.patil (3/22/2011)
Gopinath Srirangan (3/22/2011)
The question is " What is the output of the select statement from the below code
executed in sql server 10.0.1600 and with default settings " and not in SQL Server 2005 :-)

And are you sure this below code executed successfully in 2005 ?
insert into #test values
('1','A'),
('','B')


Thanks


The Insert statement would definitely not work in 2005. The feature of inserting multiple rows using VALUE caluse is introduced in 2008.


If the INSERT statement syntax is changed according to SQL Server 2005 and executed the script in SQL Server 2005 then the output is B, E, G, H for all the three select statements.
paul s-306273
paul s-306273
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3514 Visits: 1169
Too much thinking for one point...
tejaswini.patil
tejaswini.patil
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1168 Visits: 234
paul s-306273 (3/22/2011)
Too much thinking for one point...



"Point" does not matter however question matters.

I have found the question interesting and am sure there will be good learning for me.

:-)
cengland0
cengland0
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2250 Visits: 1300
Gopinath Srirangan (3/22/2011)

And are you sure this below code executed successfully in 2005 ?
insert into #test values
('1','A'),
('','B')
Thanks

It will not work in 2005. That's the server I use daily and I wish this syntax would work because it could simplify my job significantly when inserting a bunch of values manually.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search