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 12345»»»

T-SQL Expand / Collapse
Author
Message
Posted Monday, March 21, 2011 8:12 PM
SSC-Enthusiastic

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

Group: General Forum Members
Last Login: Friday, July 25, 2014 10:13 AM
Points: 157, Visits: 287
Comments posted to this topic are about the item T-SQL
Post #1081713
Posted Monday, March 21, 2011 8:14 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, June 16, 2014 9:38 AM
Points: 2,163, Visits: 2,189
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!)
Post #1081714
Posted Tuesday, March 22, 2011 12:01 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, April 9, 2014 4:48 AM
Points: 47, Visits: 55
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
Post #1081755
Posted Tuesday, March 22, 2011 12:15 AM
SSC-Enthusiastic

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

Group: General Forum Members
Last Login: Friday, July 25, 2014 10:13 AM
Points: 157, Visits: 287
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
Post #1081760
Posted Tuesday, March 22, 2011 2:52 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, April 19, 2011 1:59 AM
Points: 1,042, 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.
Post #1081802
Posted Tuesday, March 22, 2011 2:53 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, April 19, 2011 1:59 AM
Points: 1,042, Visits: 234
Interesting question.

Good learning for me.

Thanks.
Post #1081803
Posted Tuesday, March 22, 2011 2:56 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, April 19, 2011 1:59 AM
Points: 1,042, 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.
Post #1081808
Posted Tuesday, March 22, 2011 3:00 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, July 4, 2014 9:03 AM
Points: 1,415, Visits: 796
Too much thinking for one point...
Post #1081810
Posted Tuesday, March 22, 2011 3:04 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, April 19, 2011 1:59 AM
Points: 1,042, 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.

Post #1081811
Posted Tuesday, March 22, 2011 3:21 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 24, 2013 9:59 PM
Points: 1,354, Visits: 1,299
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.
Post #1081824
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse