Solved

row number without order by - TSQL

Posted on 2009-04-06
5
817 Views
Last Modified: 2012-05-06
Hello,
I have one excel sheet with some data.
I am getting the data to Sql Server 2005 by the openrowset function.
I am writing a table valued function that return the data from that excel sheet.
I want that the first field returned to be simply the row number and the other fields will be those of the excel file.
I can't sort by any of the excel field, because the table valued function should return the data in the exact same order as they were in the excel.
thanks
0
Comment
Question by:Nyana22
  • 3
  • 2
5 Comments
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 24080114
You have no guarantee of order unless you explicitly define one.  But one thing that you can do is to load the data into a #temp table that has an identity column.
0
 

Author Comment

by:Nyana22
ID: 24080192
thanks,
can we do :

select into @table

@table is a variable table?
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 24080254
No.  Table variables must be declared ahead of time.

You can do:

select ident=identity(int,1,1),* into #Temp
From <EXCEL>
0
 

Author Comment

by:Nyana22
ID: 24080302
Msg 2772, Level 16, State 1, Procedure entreeSysteme, Line 37
Cannot access temporary tables from within a function.


can i do :
select ident=identity(int,1,1),* into #Temp
From <EXCEL>

in a table valued function
0
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 500 total points
ID: 24080355
No you can't.  If you have a function UDF that gets you the data....

select ident=identity(int,1,1),yf.*
into #Temp
From dbo.YourFunction() YF

But UDF's MAY not work for that.  I don't know because i've never tried.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Query 14 57
Help with simplifying SQL 6 54
date diff with Fiscal Calendar 4 57
Substring works but need to tweak it 14 16
There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question