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

Sunday, March 25, 2012

alfanumeric counters?

Hi there,

T-sql 2005 is offering the possibility to define alfaphanumeric counters? I mean, stuff like this: a,b,c...z, a1, b1...zn...a2..

Is it possible or it must be built for yourself?

I'm awared of IDENTITY function when I ran Sql2k but it doesn't target my goal.

Thanks for your time,

You'll have to build that yourself. The question you need to ask yourself is why do you NEED an alpha-numeric identity. If you plan to process a field differently based on the format of the field then you're getting into the "database within a database" scenario which is bad.|||ok, thanks for that. At the end of the day it was related with Oracle.|||

You could do this in a Data Flow in one of two ways-

1 Use a Script Component, and included in you could also consider a custom component, at the end of the day the code will be the same, just how you package it.

2 Use a Derived Column. You would also need a row number, so either from the source, a script component or the Row Number Transform. Using the row number you could derive the a, a1, c2 etc format you require in the Derived Column using an expression.

|||Thanks Darren

Thursday, February 9, 2012

Advice on T-SQL Solution using field expressions

I have a question about a expression used in access and would like to know
if there is a way to simulate the functionality in SQL.
The qry "select NetUsage<>0 AS Expr1 FROM TBL_QUATIONTEST"
In access would return either 1 or 0 or the calculated value if there was
one, where NetUsage is a field of TBL_QUATIONTEST and would evaluate to a
boolean or calcualated result based on the condition. How can I accomplish
this SQL? At times the expression could get complicated and use several
other fields from the table TBL_QUATIONTEST in the expression.
ex:
SELECT (12.06+ ((NetUsage/750+DemadUasge)*.332)) AS Expr1
FROM TBL_QUATIONTEST
Any adivce on how I can repliacte this in SQL would help. I truely simeply
need to evaluate it to a boolean value or the caluculated reslut.
Beat Reagrds.Can you please provide DDL, sample data (both "calculated value if there was
one" and one without a calculated value), and desired results.
See http://www.aspfaq.com/5006 if you have trouble with this request...
"Tim Harvey" <papow@.yahoo.com> wrote in message
news:uyZw4zWFGHA.3900@.TK2MSFTNGP10.phx.gbl...
>I have a question about a expression used in access and would like to know
>if there is a way to simulate the functionality in SQL.
> The qry "select NetUsage<>0 AS Expr1 FROM TBL_QUATIONTEST"
> In access would return either 1 or 0 or the calculated value if there was
> one, where NetUsage is a field of TBL_QUATIONTEST and would evaluate to a
> boolean or calcualated result based on the condition. How can I
> accomplish this SQL? At times the expression could get complicated and use
> several other fields from the table TBL_QUATIONTEST in the expression.
> ex:
> SELECT (12.06+ ((NetUsage/750+DemadUasge)*.332)) AS Expr1
> FROM TBL_QUATIONTEST
> Any adivce on how I can repliacte this in SQL would help. I truely simeply
> need to evaluate it to a boolean value or the caluculated reslut.
>
> Beat Reagrds.
>|||No problem.
The Access SQL is "almost" the same as SQL Server T-SQL,
in your case with multiple fields and expressions, it is very alike.
/ola
Tim Harvey wrote:
> I have a question about a expression used in access and would like to know
> if there is a way to simulate the functionality in SQL.
> The qry "select NetUsage<>0 AS Expr1 FROM TBL_QUATIONTEST"
> In access would return either 1 or 0 or the calculated value if there was
> one, where NetUsage is a field of TBL_QUATIONTEST and would evaluate to a
> boolean or calcualated result based on the condition. How can I accomplis
h
> this SQL? At times the expression could get complicated and use several
> other fields from the table TBL_QUATIONTEST in the expression.
> ex:
> SELECT (12.06+ ((NetUsage/750+DemadUasge)*.332)) AS Expr1
> FROM TBL_QUATIONTEST
> Any adivce on how I can repliacte this in SQL would help. I truely simeply
> need to evaluate it to a boolean value or the caluculated reslut.
>
> Beat Reagrds.|||Tim Harvey wrote:
> I have a question about a expression used in access and would like to
> know if there is a way to simulate the functionality in SQL.
> The qry "select NetUsage<>0 AS Expr1 FROM TBL_QUATIONTEST"
> In access would return either 1 or 0 or the calculated value if there
> was one, where NetUsage is a field of TBL_QUATIONTEST and would
> evaluate to a boolean or calcualated result based on the condition.
> How can I accomplish this SQL? At times the expression could get
> complicated and use several other fields from the table
> TBL_QUATIONTEST in the expression.
> ex:
> SELECT (12.06+ ((NetUsage/750+DemadUasge)*.332)) AS Expr1
> FROM TBL_QUATIONTEST
> Any adivce on how I can repliacte this in SQL would help. I truely
> simeply need to evaluate it to a boolean value or the caluculated
> reslut.
> Beat Reagrds.
What you posted will work. Just watch your divisions by integers if your
intent is to keep the decimal value intact:
SELECT (12.06+ ((<Col1> / 750.0 + <Col2> ) * .332)) AS "Expr1"
FROM <Table>
David Gugick
Quest Software
www.quest.com|||In addition to the other posts:
There's no Boolean datatype in TSQL, so below will not compile:
SELECT au_lname <> 'White', au_lname FROM authors
But watch out for below:
SELECT au_lname = 'White', au_lname FROM authors
Above will produce a column names au_lname as the first column with all rows
having the string
"White" in that column. I.e., same as below (which is ANSI SQL and preferred
way):
SELECT 'White' AS au_lname, au_lname FROM authors
(Pretty crappy semantics in above, but should show the point I'm trying to m
ake.)
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Tim Harvey" <papow@.yahoo.com> wrote in message news:uyZw4zWFGHA.3900@.TK2MSFTNGP10.phx.gbl.
.
>I have a question about a expression used in access and would like to know
if there is a way to
>simulate the functionality in SQL.
> The qry "select NetUsage<>0 AS Expr1 FROM TBL_QUATIONTEST"
> In access would return either 1 or 0 or the calculated value if there was
one, where NetUsage is a
> field of TBL_QUATIONTEST and would evaluate to a boolean or calcualated re
sult based on the
> condition. How can I accomplish this SQL? At times the expression could ge
t complicated and use
> several other fields from the table TBL_QUATIONTEST in the expression.
> ex:
> SELECT (12.06+ ((NetUsage/750+DemadUasge)*.332)) AS Expr1
> FROM TBL_QUATIONTEST
> Any adivce on how I can repliacte this in SQL would help. I truely simeply
need to evaluate it to
> a boolean value or the caluculated reslut.
>
> Beat Reagrds.
>|||Not sure anyone answered the question you actually asked, change your query
from:
select NetUsage<>0 AS Expr1 FROM TBL_QUATIONTEST
To:
select case when NetUsage<>0 then 1 else 0 end as Expr1
FROM TBL_QUATIONTEST
Like Aaron said, there is not a boolean type, so you have to deal with this
in a CASE expression.
----
Louis Davidson - http://spaces.msn.com/members/drsql/
SQL Server MVP
"Arguments are to be avoided: they are always vulgar and often convincing."
(Oscar Wilde)
"Tim Harvey" <papow@.yahoo.com> wrote in message
news:uyZw4zWFGHA.3900@.TK2MSFTNGP10.phx.gbl...
>I have a question about a expression used in access and would like to know
>if there is a way to simulate the functionality in SQL.
> The qry "select NetUsage<>0 AS Expr1 FROM TBL_QUATIONTEST"
> In access would return either 1 or 0 or the calculated value if there was
> one, where NetUsage is a field of TBL_QUATIONTEST and would evaluate to a
> boolean or calcualated result based on the condition. How can I
> accomplish this SQL? At times the expression could get complicated and use
> several other fields from the table TBL_QUATIONTEST in the expression.
> ex:
> SELECT (12.06+ ((NetUsage/750+DemadUasge)*.332)) AS Expr1
> FROM TBL_QUATIONTEST
> Any adivce on how I can repliacte this in SQL would help. I truely simeply
> need to evaluate it to a boolean value or the caluculated reslut.
>
> Beat Reagrds.
>