If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Sql query to pull certain row

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-07-12, 14:13
tmcrouse tmcrouse is offline
Registered User
 
Join Date: May 2010
Posts: 6
Sql query to pull certain row

I have a very large SQL Server table and want to pull all 50 columns that are in a certain row because something in that row has invalid varchar and is causing runtime errors. It is row 9054378701 and I am not sure how to create a query to pull that specific row and all 50 columns.
Reply With Quote
  #2 (permalink)  
Old 02-07-12, 15:23
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
how do you know it's row 9054378701 ??
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-07-12, 17:09
Mark_Otmarich Mark_Otmarich is offline
Registered User
 
Join Date: Feb 2012
Posts: 7
You can use the ROW_NUMBER function to give each row a number
by using the table's index in the 'order by' clause, the rows will be ordered as they fall within the table (which should correspond to the row number you have.

I too am curious how you know that row 9054378701 has the issue

Just replace tblName with your table's name and tableID with the table's key.

Code:
WITH OrderedTable AS
(
 SELECT *, ROW_NUMBER() OVER (Order by TableID) AS 'RowNumber'
 from tblName
)
select *
from OrderedTable
where rownumber = 9054378701
Reply With Quote
  #4 (permalink)  
Old 02-08-12, 04:44
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,280
Quote:
Originally Posted by tmcrouse View Post
I have a very large SQL Server table and want to pull all 50 columns that are in a certain row because something in that row has invalid varchar and is causing runtime errors. It is row 9054378701 and I am not sure how to create a query to pull that specific row and all 50 columns.
What do you mean by "pull"? Delete that row?
Code:
DELETE 
FROM MyTAble
WHERE RowId = 9054378701
But first have a look at what that data is in that record:
Code:
SELECT * 
FROM MyTAble
WHERE RowId = 9054378701
When you've figuered out what column causes the runtime error, correct that data with correct information.
Code:
UPDATE MyTAble
SET ColumnWithError = 'Corrected data'
WHERE RowId = 9054378701
__________________
With kind regards . . . . . SQL Server 2000/2005/2008/2008 R2 Earned beers: 16
Wim
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On