Showing posts with label t-sql. Show all posts
Showing posts with label t-sql. Show all posts

Thursday, March 22, 2012

computed column formula

Is it possible to retrieve the formula associated with a computed column using t-SQL? I can use COLUMNPROPERTY( id, column, 'IsComputed') to find the computed columns, but how do I get the formula itself?

Thanks,

Mable

sp_helptext 'TableName', 'Computed Column Name'

For eg


CREATE TABLE T(i int, j AS i *2)

INSERT INTO T(i) VALUES(10)
SELECT * FROM T

sp_helptext 'T', 'j'

|||

Thank you! That is just what I needed.

--Mable

computed column formula

Is it possible to retrieve the formula associated with a computed column using t-SQL? I can use COLUMNPROPERTY( id, column, 'IsComputed') to find the computed columns, but how do I get the formula itself?

Thanks,

Mable

sp_helptext 'TableName', 'Computed Column Name'

For eg


CREATE TABLE T(i int, j AS i *2)

INSERT INTO T(i) VALUES(10)
SELECT * FROM T

sp_helptext 'T', 'j'

|||

Thank you! That is just what I needed.

--Mable

Thursday, March 8, 2012

Complex T-SQL

Guys
I have a data table that contains emails that could come from one or
more source. I want to add a column to the table to reflect the
combination of sources that the record came from.
Basically I am trying to create the hybird_src and the hybrid tables
from the data_table. Then I want to update a new column on data table
with hybrid_id.
I know I can do this with a cursor, but it seems like there should be a
better (set based) way to accomplish this. Does anyone have any
suggestions?
create table #data_table(email_id int,src_id int)
--raw data
insert into #data_table (1,5)
insert into #data_table (1,6)
insert into #data_table (1,7)
insert into #data_table (2,5)
insert into #data_table (2,6)
insert into #data_table (2,7)
insert into #data_table (3,5)
insert into #data_table (3,6)
insert into #data_table (3,7)
insert into #data_table (4,5)
insert into #data_table (4,6)
insert into #data_table (5,5)
insert into #data_table (5,9)
insert into #data_table (5,4)
insert into #data_table (5,20)
insert into #data_table (6,20)
insert into #data_table (6,5)
insert into #data_table (6,9)
insert into #data_table (6,4)
create table #hybrid_src (hybrid_id int,src_id int)
--results I am looking for
insert into #hybrid_src (1,5)
insert into #hybrid_src (1,6)
insert into #hybrid_src (1,7)
insert into #hybrid_src (2,5)
insert into #hybrid_src (2,6)
insert into #hybrid_src (3,5)
insert into #hybrid_src (3,9)
insert into #hybrid_src (3,4)
insert into #hybrid_src (3,20)
create table #hybrid(hybrid_id int,hybrid_name varchar(200))
--results I am looking for
INSERT INTO #hybrid(1,'5,6,7')
INSERT INTO #hybrid(2,'5,6')
INSERT INTO #hybrid(3,'4,5,9,20')Dave wrote:
> Guys
> I have a data table that contains emails that could come from one or
> more source. I want to add a column to the table to reflect the
> combination of sources that the record came from.
> Basically I am trying to create the hybird_src and the hybrid tables
> from the data_table. Then I want to update a new column on data table
> with hybrid_id.
> I know I can do this with a cursor, but it seems like there should be a
> better (set based) way to accomplish this. Does anyone have any
> suggestions?
>
Why would you want to destroy the apparently sensible and practical
design you already have by kludging it into the "hybrid" tables that
you say you want? Concatenating lots of values together in a column
just results in redundancy and denormalization. If you need to display
it that way in a report then do it in your presentation tier, not in
the database.
David Portas
SQL Server MVP
--|||I am trying to accurately reflect which source an email came from.
Since an email can belong to more than one source it makes since (at
least to me so far) to report on a hybrid of all the valid sources.
If I model email transactions in a Datamart the fact grain would be the
email. I need a source dimension.
Any feedback on this would be very helpful. Including a better way to
model this.

Sunday, February 12, 2012

Compatibility between SQL2000 and SQL2005

Will my old applications with standard T-SQL code work againt the new
SQL2005 without modifications ?
KayHi
It depends. Mostly yes, but if you are using any syntax that Microsoft has
been warning will be depricated, or any undocumented functions, no.
You will have to test.
Regards
Mike
"Kay-Christian Hansen" wrote:

> Will my old applications with standard T-SQL code work againt the new
> SQL2005 without modifications ?
> Kay
>
>|||If there is any breaking bits, MS will issue a document before release. Thus
far, I have seen nothing that is not backward compatible in T-SQL. If you
follow good standards, you should not have any problems. There are new
additions to T-SQL in SQL 2005, however, that you might want to move to for
perf, etc.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
****************************************
*******
Think outside the box!
****************************************
*******
"Kay-Christian Hansen" <Kay@.Tempus.no> wrote in message
news:OhbU4zbOFHA.2252@.TK2MSFTNGP15.phx.gbl...
> Will my old applications with standard T-SQL code work againt the new
> SQL2005 without modifications ?
> Kay
>|||There are a few changes, for example with the new schema getup,
INFORMATION_SCHEMA.SCHEMATA doesn't work like it currently does in 2000.
There are also some very forceful changes to non-ansi outer joins (*=, =*).
For the most part, backward compatibility is pristine, but there are several
other things going forward that, while you don't have to deal with it right
away, you should definitely visit before the next version after 2005.
You really should be asking this kind of question in the SQL Server 2005
newsgroups.
http://www.aspfaq.com/sql2005/show.asp?id=1
This is my signature. It is a general reminder.
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.
"Kay-Christian Hansen" <Kay@.Tempus.no> wrote in message
news:OhbU4zbOFHA.2252@.TK2MSFTNGP15.phx.gbl...
> Will my old applications with standard T-SQL code work againt the new
> SQL2005 without modifications ?
> Kay
>