dbTalk Databases Forums  

row no in sql query

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss row no in sql query in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Vikram
 
Posts: n/a

Default row no in sql query - 11-15-2005 , 04:07 AM






How can i get a row no column in a query... i just want to check if a row no
of a row is more than a constant number than set some flag in another column




Reply With Quote
  #2  
Old   
David Portas
 
Posts: n/a

Default Re: row no in sql query - 11-15-2005 , 04:27 AM






Specifically for DTS or in a query generally?

In a SQL query a "row number" normally means a "ranking" or "sequence"
based on some sort order. For example, here's a query for a row number
based on au_id:

SELECT au_id, au_lname, au_fname,
(SELECT COUNT(*)
FROM pubs.dbo.authors
WHERE au_id <= A.au_id) AS row_no
FROM pubs.dbo.authors AS A
ORDER BY au_id ;

Run this both with and without the ORDER BY to demonstrate that the
row_no is derived in the subquery - it has nothing to do with the
displayed order or some notional ordering in the table because no such
order exists for the query itself.

In DTS, when transforming a non-relational data source such as a text
file you may want to include an incrementing row number in the
transformation. To do this, you can create a global variable and then
add the following lines to the ActiveX row transform:

DTSGlobalVariables("row_no").Value = DTSGlobalVariables("row_no").Value
+ 1
....
DTSDestination("row_no") = DTSGlobalVariables("row_no").Value

Hope this helps.

--
David Portas
SQL Server MVP
--


Reply With Quote
  #3  
Old   
Vikram
 
Posts: n/a

Default Re: row no in sql query - 11-17-2005 , 07:12 AM



But if i have many join than this does not work
"David Portas" <REMOVE_BEFORE_REPLYING_dportas (AT) acm (DOT) org> wrote

Quote:
Specifically for DTS or in a query generally?

In a SQL query a "row number" normally means a "ranking" or "sequence"
based on some sort order. For example, here's a query for a row number
based on au_id:

SELECT au_id, au_lname, au_fname,
(SELECT COUNT(*)
FROM pubs.dbo.authors
WHERE au_id <= A.au_id) AS row_no
FROM pubs.dbo.authors AS A
ORDER BY au_id ;

Run this both with and without the ORDER BY to demonstrate that the
row_no is derived in the subquery - it has nothing to do with the
displayed order or some notional ordering in the table because no such
order exists for the query itself.

In DTS, when transforming a non-relational data source such as a text
file you may want to include an incrementing row number in the
transformation. To do this, you can create a global variable and then
add the following lines to the ActiveX row transform:

DTSGlobalVariables("row_no").Value = DTSGlobalVariables("row_no").Value
+ 1
...
DTSDestination("row_no") = DTSGlobalVariables("row_no").Value

Hope this helps.

--
David Portas
SQL Server MVP
--




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.