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

Select with Row ID

 
   Database Help (Home) -> Programming RSS
Next:  Find broken stuff  
Author Message
ArunDhaJ

External


Since: May 22, 2008
Posts: 24



(Msg. 1) Posted: Mon Aug 04, 2008 9:41 pm
Post subject: Select with Row ID
Archived from groups: microsoft>public>sqlserver>programming (more info?)

Hi All,
I'm having a select statement like this:
Select SName, SDepartment from Department

what I need is that, a select statement which adds a new column RowId
with dynamically generated serial numbers. The output should be like
this:

RowId SName SDepartment
1 Abc CSE
2 Bcd ECE
3 Cde EEE

Thanks in Advance

Regards
ArunDhaJ

 >> Stay informed about: Select with Row ID 
Back to top
Login to vote
sp

External


Since: Apr 29, 2008
Posts: 27



(Msg. 2) Posted: Mon Aug 04, 2008 10:36 pm
Post subject: RE: Select with Row ID [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

SQL SERVER 2005
Select
ROW_NUMBER() OVER(ORDER BY SName) as RowID,
SName,
SDepartment
from Department

HTH,

"ArunDhaJ" wrote:

> Hi All,
> I'm having a select statement like this:
> Select SName, SDepartment from Department
>
> what I need is that, a select statement which adds a new column RowId
> with dynamically generated serial numbers. The output should be like
> this:
>
> RowId SName SDepartment
> 1 Abc CSE
> 2 Bcd ECE
> 3 Cde EEE
>
> Thanks in Advance
>
> Regards
> ArunDhaJ
>

 >> Stay informed about: Select with Row ID 
Back to top
Login to vote
ArunDhaJ

External


Since: May 22, 2008
Posts: 24



(Msg. 3) Posted: Mon Aug 04, 2008 11:33 pm
Post subject: Re: Select with Row ID [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

I'm using SQL server 2000. Is there any way to achieve this same?

Regards
ArunDhaJ
 >> Stay informed about: Select with Row ID 
Back to top
Login to vote
Plamen Ratchev

External


Since: Jan 10, 2008
Posts: 1007



(Msg. 4) Posted: Tue Aug 05, 2008 1:32 am
Post subject: Re: Select with Row ID [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On SQL Server 2005 you can use ROW_NUMBER:

SELECT ROW_NUMBER() OVER(ORDER BY SName, SDepartment) AS RowId,
SName, SDepartment
FROM Department;

Plamen Ratchev
http://www.SQLStudio.com
 >> Stay informed about: Select with Row ID 
Back to top
Login to vote
Uri Dimant

External


Since: Aug 24, 2003
Posts: 1744



(Msg. 5) Posted: Tue Aug 05, 2008 9:45 am
Post subject: Re: Select with Row ID [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi
Is SDepartment unique?

SELECT *,(SELECT COUNT(*) FROM tbl T WHERE T.SDepartment <=tbl.SDepartment )
as Row
FROM tbl

"ArunDhaJ" wrote in message

> I'm using SQL server 2000. Is there any way to achieve this same?
>
> Regards
> ArunDhaJ
 >> Stay informed about: Select with Row ID 
Back to top
Login to vote
shashank shende

External


Since: Apr 22, 2010
Posts: 1



(Msg. 6) Posted: Thu Apr 22, 2010 10:17 pm
Post subject: answer [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi All,
I'm having a select statement like this:
Select SName, SDepartment from Department

what I need is that, a select statement which adds a new column RowId
with dynamically generated serial numbers. The output should be like
this:

RowId SName SDepartment
1 Abc CSE
2 Bcd ECE
3 Cde EEE

Thanks in Advance



do you get the answer because me also want to know.



ArunDhaJ wrote:

Select with Row ID
05-Aug-08

Hi All,
I'm having a select statement like this:
Select SName, SDepartment from Department

what I need is that, a select statement which adds a new column RowId
with dynamically generated serial numbers. The output should be like
this:

RowId SName SDepartment
1 Abc CSE
2 Bcd ECE
3 Cde EEE

Thanks in Advance

Regards
ArunDhaJ

Previous Posts In This Thread:

On Tuesday, August 05, 2008 1:32 AM
Plamen Ratchev wrote:

Re: Select with Row ID
On SQL Server 2005 you can use ROW_NUMBER:

SELECT ROW_NUMBER() OVER(ORDER BY SName, SDepartment) AS RowId,
SName, SDepartment
FROM Department;

Plamen Ratchev
http://www.SQLStudio.com

On Tuesday, August 05, 2008 1:36 AM
s wrote:

SQL SERVER 2005Select ROW_NUMBER() OVER(ORDER BY SName) as
SQL SERVER 2005
Select
ROW_NUMBER() OVER(ORDER BY SName) as RowID,
SName,
SDepartment
from Department

HTH,

"ArunDhaJ" wrote:

On Tuesday, August 05, 2008 2:45 AM
Uri Dimant wrote:

HiIs SDepartment unique?
Hi
Is SDepartment unique?

SELECT *,(SELECT COUNT(*) FROM tbl T WHERE T.SDepartment <=tbl.SDepartment )
as Row
FROM tbl

On Tuesday, August 05, 2008 5:01 AM
ArunDhaJ wrote:

Select with Row ID
Hi All,
I'm having a select statement like this:
Select SName, SDepartment from Department

what I need is that, a select statement which adds a new column RowId
with dynamically generated serial numbers. The output should be like
this:

RowId SName SDepartment
1 Abc CSE
2 Bcd ECE
3 Cde EEE

Thanks in Advance

Regards
ArunDhaJ

On Tuesday, August 05, 2008 5:01 AM
ArunDhaJ wrote:

I'm using SQL server 2000. Is there any way to achieve this same?RegardsArunDhaJ
I am using SQL server 2000. Is there any way to achieve this same?

Regards
ArunDhaJ


Submitted via EggHeadCafe - Software Developer Portal of Choice
WPF Reflection Effect
http://www.eggheadcafe.com/tutorials/aspnet/8cc84aa8-3b44-4037-beab-49...6e20b9b
 >> Stay informed about: Select with Row ID 
Back to top
Login to vote
Uri Dimant

External


Since: Aug 24, 2003
Posts: 1744



(Msg. 7) Posted: Fri Apr 23, 2010 3:25 am
Post subject: Re: answer [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi
In SQL Server 2005 and onwards you can use ROW_NUMBER() system function,
please see BOL for details
In SQL Server 2000 that could be tricky
See if the below works.
Select SName, SDepartment,
(SELECT COUNT(*) FROM Department d WHERE
d.SDepartment<=Department.SDepartment) AS RowId
from Department

Note , I would not pregfer to compare the table by using VARCHAR(n) column
, use INT unique column for such reportts like EmployeeID


<shashank shende> wrote in message

> Hi All,
> I'm having a select statement like this:
> Select SName, SDepartment from Department
>
> what I need is that, a select statement which adds a new column RowId
> with dynamically generated serial numbers. The output should be like
> this:
>
> RowId SName SDepartment
> 1 Abc CSE
> 2 Bcd ECE
> 3 Cde EEE
>
> Thanks in Advance
>
>
>
> do you get the answer because me also want to know.
>
>
>
> ArunDhaJ wrote:
>
> Select with Row ID
> 05-Aug-08
>
> Hi All,
> I'm having a select statement like this:
> Select SName, SDepartment from Department
>
> what I need is that, a select statement which adds a new column RowId
> with dynamically generated serial numbers. The output should be like
> this:
>
> RowId SName SDepartment
> 1 Abc CSE
> 2 Bcd ECE
> 3 Cde EEE
>
> Thanks in Advance
>
> Regards
> ArunDhaJ
>
> Previous Posts In This Thread:
>
> On Tuesday, August 05, 2008 1:32 AM
> Plamen Ratchev wrote:
>
> Re: Select with Row ID
> On SQL Server 2005 you can use ROW_NUMBER:
>
> SELECT ROW_NUMBER() OVER(ORDER BY SName, SDepartment) AS RowId,
> SName, SDepartment
> FROM Department;
>
> Plamen Ratchev
> http://www.SQLStudio.com
>
> On Tuesday, August 05, 2008 1:36 AM
> s wrote:
>
> SQL SERVER 2005Select ROW_NUMBER() OVER(ORDER BY SName) as
> SQL SERVER 2005
> Select
> ROW_NUMBER() OVER(ORDER BY SName) as RowID,
> SName,
> SDepartment
> from Department
>
> HTH,
>
> "ArunDhaJ" wrote:
>
> On Tuesday, August 05, 2008 2:45 AM
> Uri Dimant wrote:
>
> HiIs SDepartment unique?
> Hi
> Is SDepartment unique?
>
> SELECT *,(SELECT COUNT(*) FROM tbl T WHERE T.SDepartment
> <=tbl.SDepartment )
> as Row
> FROM tbl
>
> On Tuesday, August 05, 2008 5:01 AM
> ArunDhaJ wrote:
>
> Select with Row ID
> Hi All,
> I'm having a select statement like this:
> Select SName, SDepartment from Department
>
> what I need is that, a select statement which adds a new column RowId
> with dynamically generated serial numbers. The output should be like
> this:
>
> RowId SName SDepartment
> 1 Abc CSE
> 2 Bcd ECE
> 3 Cde EEE
>
> Thanks in Advance
>
> Regards
> ArunDhaJ
>
> On Tuesday, August 05, 2008 5:01 AM
> ArunDhaJ wrote:
>
> I'm using SQL server 2000. Is there any way to achieve this
> same?RegardsArunDhaJ
> I am using SQL server 2000. Is there any way to achieve this same?
>
> Regards
> ArunDhaJ
>
>
> Submitted via EggHeadCafe - Software Developer Portal of Choice
> WPF Reflection Effect
> http://www.eggheadcafe.com/tutorials/aspnet/8cc84aa8-3b44-4037-beab-49...6e20b9b
 >> Stay informed about: Select with Row ID 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
query perfomance issue with Select statment in the Select .. - Hi all, Using SQL 2000 sp4 This query works, put takes about 11 to 20 seconds. Just trying to be more effient with it and maybe write it better. I hope I explain this correctly so you guys can understnd. --Orders table has 869,000 rows --Table..

How to select specific line in select statement from a giv.. - TableName : TableX Column 1 : name (single line) Column 2 : Comments (multiple line) In "Column2" i have comments which are all about roughtly 20 lines but can vary. What i want to do is for example i want to write a select query which will di...

adding another row in the select? join? nested select - working in asp.net 2.0. I have a dropdownlist with a sqldatasource selectcommand. Currently just doing a select distinct * from table order by code (the second field). I'm trying to stay only in the markup, and I'd like to add a temporary (for the sake...

SELECT/INSERT SELECT performance issue - Hello there, I need your advices/comments. After in-place upgrade to SQL Server 2005, we've noticed some strange query optimizer behavior when executing an INSERT SELECT query. There were absolutely no performance problems with this query in MSSQL2k ...

Select the balance of a select top(x) - HI All, If I have a statement that does a count on the top 5 rows, how can I then select the count of the balance of the rows not counted in the original top 5 so my sql looks like this: SELECT TOP (5) dbo.Process.ProcessName,..
   Database Help (Home) -> Programming 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 ]