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

TSQL Expand / Collapse
Author
Message
Posted Wednesday, March 25, 2009 8:17 PM
SSC-Enthusiastic

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

Group: General Forum Members
Last Login: Tuesday, September 25, 2012 4:03 AM
Points: 185, Visits: 52
Comments posted to this topic are about the item TSQL
Post #683808
Posted Thursday, March 26, 2009 12:57 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, July 10, 2014 12:43 AM
Points: 217, Visits: 170
Hi there

I work in a SQL 2000 developer edition. when I run the provided script, it runs successfully returning rows 1 through 6.

Only if I run the script, without the from subselect, does it return a conversion error.

Why is that?

Marius
Post #683865
Posted Thursday, March 26, 2009 1:02 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 11:53 PM
Points: 1,226, Visits: 759
When the SELECT statement is compiled for the INSERT, the first value is implicitly taken as an INT. In the UNIONs, as each SELECT is added, they must match this data type.


If that is the correct explanation, would the next statement work?
Insert into test Select 'A' union Select 1;

(Answer: No)






Dutch Anti-RBAR League
Post #683868
Posted Thursday, March 26, 2009 1:21 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, June 12, 2014 2:20 AM
Points: 23, Visits: 137
Hi,
The answer given here is wrong.The correct answer will be
1
2
3
4
5
6

Thanks.
Post #683874
Posted Thursday, March 26, 2009 1:24 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, August 19, 2014 4:35 AM
Points: 2,185, Visits: 194
Hi

The given script will work in SQL Server 2000 giving the results 1,2,3,4,5,6.
In SQL Server 2008 it fails saying conversion failed when converting the varchar value 'A' to data type int.


Post #683876
Posted Thursday, March 26, 2009 2:05 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, January 22, 2014 10:02 AM
Points: 284, Visits: 54
In future must show the version of MS SQL Server in order to prevent a misunderstanding.
I answered right for version 2000, but for 2008 I made a mistake.
Post #683887
Posted Thursday, March 26, 2009 2:23 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: Friday, August 29, 2014 2:13 AM
Points: 3,237, Visits: 1,267
On SQL 2005 it also works, so in that case answer c is the correct one.
Post #683893
Posted Thursday, March 26, 2009 2:42 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, July 10, 2014 12:43 AM
Points: 217, Visits: 170
I'm glad to see my thinking (from a SQL 2000 point of view) was at least in line with some other folks as well.
Unfortunately this didn't get us the points

I agree: indicating the version of SQL the script was written in would have helped...
Post #683898
Posted Thursday, March 26, 2009 2:44 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, August 29, 2014 9:51 AM
Points: 1,070, Visits: 900
What a crap question.

Can someone adjust this, its pretty bad. Plain wrong, in fact.



Post #683899
Posted Thursday, March 26, 2009 2:55 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, July 30, 2014 8:23 AM
Points: 2,025, Visits: 2,521
I ran this script it in sql2000. it is working fine. it shows 1,2,3,4,5,6. so the correct answer is c.





karthik
Post #683907
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse