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

Computed column Expand / Collapse
Author
Message
Posted Saturday, November 6, 2010 3:00 PM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Tuesday, July 23, 2013 6:34 AM
Points: 654, Visits: 265
Comments posted to this topic are about the item Computed column
Post #1016897
Posted Saturday, November 6, 2010 3:06 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:35 AM
Points: 7,874, Visits: 9,613
Now wouldn't it be fun if a unification capability were added to SQL so that you in an insert statement could specify the values of some computed columns and leave out the values of some of the non-computed columns and have the database engine compute the set of (new) rows that would satisfy the computations and any constraings (keys, check constraings, etc) and insert them all.

Or maybe not - probably safer to stick to doing that sort of thing in prolog or parlog or something.


Tom
Post #1016898
Posted Monday, November 8, 2010 12:28 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:55 AM
Points: 13,570, Visits: 11,383
Nice question. I was a bit distracted by the select 1 from #table statement, but opted to choose for the error anyway.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1017018
Posted Monday, November 8, 2010 2:15 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, November 24, 2014 8:30 AM
Points: 1,417, Visits: 806
Interesting question.

Keep them coming...
Post #1017037
Posted Monday, November 8, 2010 6:38 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, November 4, 2014 12:48 PM
Points: 2,818, Visits: 2,566
I was looking for the trick, but couldn't find one. Nice question. Thanks.
Post #1017146
Posted Monday, November 8, 2010 6:46 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 10:23 AM
Points: 2,630, Visits: 4,041
Nice easy one for a Monday morning. Thanks.

I was working with computed columns last week and ran across this issue.
Post #1017158
Posted Monday, November 8, 2010 8:34 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: Thursday, July 17, 2014 10:56 AM
Points: 3,924, Visits: 1,607

Create Table #Test (a int, b int, C as a+b )
go
insert into #test values (3,4)
insert into #test values (1,7)
go
select * from #test
order by 1
go
drop table #test
go



Isn't it funny that when you say order by 1, sql server assumes 1 as column and gives result order by column 1 but at the same time when you execute

select 1 from #test

you get result as 1


SQL DBA.
Post #1017229
Posted Monday, November 8, 2010 8:46 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 31, 2013 8:01 AM
Points: 1,228, Visits: 1,046
Nice question for a monday.

I Also give this question Five stars for have correct code and no typos in the question or the answer.
Post #1017239
Posted Monday, November 8, 2010 10:12 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:55 AM
Points: 13,570, Visits: 11,383
SanjayAttray (11/8/2010)


Isn't it funny that when you say order by 1, sql server assumes 1 as column and gives result order by column 1 but at the same time when you execute

select 1 from #test

you get result as 1


That's because when you use 1 in ORDER BY, you are giving an ordinal position of a column to sort by, while with the SELECT statement, the 1 is an expression.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1017295
Posted Monday, November 8, 2010 10:53 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, September 5, 2014 2:00 PM
Points: 2,160, Visits: 2,191
Nice question, I would have gotten it wrong had the option for the problem with + not been there. (I didn't see the computed column so once I went looking for the + I immediately knew what was going to happen.

Thanks!
Post #1017329
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse