Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Strange SELECT statement

 
   Database Forums (Home) -> Client RSS
Next:  MAINFRAME Training with IBM Certification  
Author Message
Deiny García Pérez

External


Since: Feb 25, 2008
Posts: 1



(Msg. 1) Posted: Mon Feb 25, 2008 10:11 am
Post subject: Strange SELECT statement
Archived from groups: microsoft>public>sqlserver>clients (more info?)

Hello Everyone...

I have a particular Select statement to do... for example I want a Select
like this:

Select Name, SpecialNo from emp... etc. and get result like this:

Name SpecialNo
Peter 5
John 10
Daniel 15
Bob 20

But the problem is this, I need SpecialNo to be a generated number, not a
real exixting data and also I want this number to increment in every row (in
this case is like John's SpecialNo = Peter's SpecialNo + 5 and so on)

Please, help me, thanks in advance

 >> Stay informed about: Strange SELECT statement 
Back to top
Login to vote
Johnny

External


Since: Feb 25, 2008
Posts: 6



(Msg. 2) Posted: Mon Feb 25, 2008 4:01 pm
Post subject: Re: Strange SELECT statement [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Howdy,

You're gonna have to create a calculated column and probably gonna have to
use the @@identity option.

If you give me some more information in terms of the values of the SpecialNo
column, I may be able to provide more specific help.

Cheers,

John
http://www.sisense.com
"Business Intelligence For Everybody!"


"Deiny García Pérez" wrote in message

> Hello Everyone...
>
> I have a particular Select statement to do... for example I want a
> Select like this:
>
> Select Name, SpecialNo from emp... etc. and get result like this:
>
> Name SpecialNo
> Peter 5
> John 10
> Daniel 15
> Bob 20
>
> But the problem is this, I need SpecialNo to be a generated number, not a
> real exixting data and also I want this number to increment in every row
> (in this case is like John's SpecialNo = Peter's SpecialNo + 5 and so on)
>
> Please, help me, thanks in advance
>

 >> Stay informed about: Strange SELECT statement 
Back to top
Login to vote
Mike C#

External


Since: Jul 27, 2006
Posts: 212



(Msg. 3) Posted: Mon Feb 25, 2008 8:01 pm
Post subject: Re: Strange SELECT statement [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Assuming you have a table like the following:

CREATE TABLE #emp ([Name] VARCHAR(20));
GO

INSERT INTO #emp ([Name]) VALUES ('Peter');
INSERT INTO #emp ([Name]) VALUES ('John');
INSERT INTO #emp ([Name]) VALUES ('Daniel');
INSERT INTO #emp ([Name]) VALUES ('Bob');
GO

SQL 2005 solution:

SELECT [Name], ROW_NUMBER() OVER (ORDER BY [Name]) * 5 AS SpecialNo
FROM #emp;
GO

SQL 2000 solution:

SELECT e1.[Name], COUNT(*) * 5 AS SpecialNo
FROM #emp e1
INNER JOIN #emp e2
ON e2.[Name] <= e1.[Name]
GROUP BY e1.[Name]
GO


"Deiny García Pérez" wrote in message

> Hello Everyone...
>
> I have a particular Select statement to do... for example I want a
> Select like this:
>
> Select Name, SpecialNo from emp... etc. and get result like this:
>
> Name SpecialNo
> Peter 5
> John 10
> Daniel 15
> Bob 20
>
> But the problem is this, I need SpecialNo to be a generated number, not a
> real exixting data and also I want this number to increment in every row
> (in this case is like John's SpecialNo = Peter's SpecialNo + 5 and so on)
>
> Please, help me, thanks in advance
>
 >> Stay informed about: Strange SELECT statement 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Strange sorting behaviour sql 20004 SP4 - Hi (Using SQL server 2000 SP4) I´m having some strange problems with sorting on a joined table which is not in the result set I have the following DB able structure: Clinic -> Address -> Country The problem is i want a clinic list order by the....

Strange behaviour in record ordering - Hi, Can anyone suggest what is going wrong here? I have created a stored procedure in SQL2005 Express, which builds a temp table, messes with data a bit, and returns this data. The order of the returned records is important. This is the last line of....

Strange error while executing query - Hi, I have an unexpected error while executing the query below If I run it in Management Studio it will work fine, but if I run it using my code in C# on the same machine it will fail with the following exception: SqlDateTime overflow. Must be between...

Select with a Where that looks up in a XML column... Possi.. - Hi, We have a serie of objects stored in the database as xml (ex: MyClass is stored in the table MyClasses in the field XML_MyClassObj which contains the an instance of the class serialized to XML). We did that because it was easier to serialize..

Timeout Expired With SELECT/WHERE - All, I am using C# to a SQL Server 2005 database using an SqlDataAdapter, SqlCommand and SqlDataReader. When running the query I receive the following exception: Timeout expired. The timeout period elapsed prior to completion of the operation or the....
   Database Forums (Home) -> Client All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]