473,490 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

SELECT * not returning any rows, but SELECT COL_NAME does!

I have a table which is returning inconsistent results when I query
it!

In query analyzer:

If I do "SELECT * FROM TABLE_NAME" I get no rows returned.

If I do "SELECT COL1, COL2 FROM TABLE_NAME" I get 4 rows returned.

In Enterprise manager:

If I do "return all rows" I get 4 rows returned, and the SQL is listed
as being "SELECT * FROM dbo.TABLE_NAME".

I've tried adding the "dbo." before my table name in QA, but it seems
to make no difference.

I'm using SQL Server 2000, which is apparently 8.00534.

Can anyone help me, or give me ideas about what to check?

Thanks,

Rowland.
Jul 20 '05 #1
9 10744
Hi,

Can you execute the below statement from QA,

update statistics tablename

After this try to execute select * from table

Thanks
Hari
MCDBA
"Rowland Hills" <ro**********@hotmail.com> wrote in message
news:4d**************************@posting.google.c om...
I have a table which is returning inconsistent results when I query
it!

In query analyzer:

If I do "SELECT * FROM TABLE_NAME" I get no rows returned.

If I do "SELECT COL1, COL2 FROM TABLE_NAME" I get 4 rows returned.

In Enterprise manager:

If I do "return all rows" I get 4 rows returned, and the SQL is listed
as being "SELECT * FROM dbo.TABLE_NAME".

I've tried adding the "dbo." before my table name in QA, but it seems
to make no difference.

I'm using SQL Server 2000, which is apparently 8.00534.

Can anyone help me, or give me ideas about what to check?

Thanks,

Rowland.

Jul 20 '05 #2
> In query analyzer:

If I do "SELECT * FROM TABLE_NAME" I get no rows returned.

If I do "SELECT COL1, COL2 FROM TABLE_NAME" I get 4 rows returned.
Scary... I'd do a consistency check for the database/table.

--
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=d...blic.sqlserver
"Rowland Hills" <ro**********@hotmail.com> wrote in message
news:4d**************************@posting.google.c om... I have a table which is returning inconsistent results when I query
it!

In query analyzer:

If I do "SELECT * FROM TABLE_NAME" I get no rows returned.

If I do "SELECT COL1, COL2 FROM TABLE_NAME" I get 4 rows returned.

In Enterprise manager:

If I do "return all rows" I get 4 rows returned, and the SQL is listed
as being "SELECT * FROM dbo.TABLE_NAME".

I've tried adding the "dbo." before my table name in QA, but it seems
to make no difference.

I'm using SQL Server 2000, which is apparently 8.00534.

Can anyone help me, or give me ideas about what to check?

Thanks,

Rowland.

Jul 20 '05 #3
> I'm using SQL Server 2000, which is apparently 8.00534.

In addition to the other suggestions, you might want to make sure you're at
least up to SP3 (8.00.760).

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
Jul 20 '05 #4
Rowland,
If "TABLE_NAME" is a view, then I have seen this kind of problem if
there are subqueries in the view that retrieve multiple rows. But even that
would depend on a where clause, which you don't have.
If "TABLE_NAME" is truly a table, you probably need to rebuild the
table. First try rebuilding the table statistics, but I don't think that
will solve the problem.
Best regards,
Chuck Conover
www.TechnicalVideos.net


"Rowland Hills" <ro**********@hotmail.com> wrote in message
news:4d**************************@posting.google.c om...
I have a table which is returning inconsistent results when I query
it!

In query analyzer:

If I do "SELECT * FROM TABLE_NAME" I get no rows returned.

If I do "SELECT COL1, COL2 FROM TABLE_NAME" I get 4 rows returned.

In Enterprise manager:

If I do "return all rows" I get 4 rows returned, and the SQL is listed
as being "SELECT * FROM dbo.TABLE_NAME".

I've tried adding the "dbo." before my table name in QA, but it seems
to make no difference.

I'm using SQL Server 2000, which is apparently 8.00534.

Can anyone help me, or give me ideas about what to check?

Thanks,

Rowland.

Jul 20 '05 #5
"TABLE_NAME" is indeed the name of my table, not a view on it,
unfortunately!

I've tried the "update statistics TABLE_NAME" command, which had no
effect, and the "DBCC CHECKDB" which reported no errors.

When you say "rebuild the table", do you simply mean drop it and
create it again, or so I need to do something more?

Thanks for your help,

Rowland.

"Chuck Conover" <cc******@commspeed.net> wrote in message news:<10***************@news.commspeed.net>...
Rowland,
If "TABLE_NAME" is a view, then I have seen this kind of problem if
there are subqueries in the view that retrieve multiple rows. But even that
would depend on a where clause, which you don't have.
If "TABLE_NAME" is truly a table, you probably need to rebuild the
table. First try rebuilding the table statistics, but I don't think that
will solve the problem.
Best regards,
Chuck Conover
www.TechnicalVideos.net


"Rowland Hills" <ro**********@hotmail.com> wrote in message
news:4d**************************@posting.google.c om...
I have a table which is returning inconsistent results when I query
it!

In query analyzer:

If I do "SELECT * FROM TABLE_NAME" I get no rows returned.

If I do "SELECT COL1, COL2 FROM TABLE_NAME" I get 4 rows returned.

In Enterprise manager:

If I do "return all rows" I get 4 rows returned, and the SQL is listed
as being "SELECT * FROM dbo.TABLE_NAME".

I've tried adding the "dbo." before my table name in QA, but it seems
to make no difference.

I'm using SQL Server 2000, which is apparently 8.00534.

Can anyone help me, or give me ideas about what to check?

Thanks,

Rowland.

Jul 20 '05 #6
Rowland,
First, only "rebuild" if you are sure the table is corrupted. I have
included how to rebuild below, but I've never seen a table corrupted in SQL
Server 2000, which isn't to say it isn't happening.
One more thing to look at first. Does "TABLE_NAME" exist in your db
with multiple users? IE: dbo.TABLE_NAME and myuserID.TABLE_NAME. And, are
you doing both queries from the same place? ie: both in SQL Query
Analyzer, or are you doing one in a procedure or application? It just
sounds like you might be querying 2 different tables. I think this is a
much more likely reason than that the table is corrupted.

By "rebuilding the table", you can just drop and re-add if you don't
need to keep the data in the table, but, if you want to keep the data, this
is what I would do.

1. Create another table with the same structure
2. Insert all the data from the corrupted table (we're assuming it's
corrupted) into the new table(ie:
insert into new_table (col1, col2, col3...)
select col1, col2, col3... from old_table
3. Drop the old table
4. Rename the new table to the old table name (ie: exec sp_rename
'new_table', 'old_table'
You'll get a warning that says:

"Caution: Changing any part of an object name could break scripts and stored
procedures.
The object was renamed to 'TemptblName'."

Which you should definitely consider before dropping the old table. ie:
What foreign keys, triggers, and views reference the old table. I think the
views will be ok, but the FK and triggers will need to be re-added.

Best regards,
Chuck Conover
www.TechnicalVideos.net
"Rowland Hills" <ro**********@hotmail.com> wrote in message
news:4d**************************@posting.google.c om...
"TABLE_NAME" is indeed the name of my table, not a view on it,
unfortunately!

I've tried the "update statistics TABLE_NAME" command, which had no
effect, and the "DBCC CHECKDB" which reported no errors.

When you say "rebuild the table", do you simply mean drop it and
create it again, or so I need to do something more?

Thanks for your help,

Rowland.

"Chuck Conover" <cc******@commspeed.net> wrote in message

news:<10***************@news.commspeed.net>...
Rowland,
If "TABLE_NAME" is a view, then I have seen this kind of problem if
there are subqueries in the view that retrieve multiple rows. But even that would depend on a where clause, which you don't have.
If "TABLE_NAME" is truly a table, you probably need to rebuild the
table. First try rebuilding the table statistics, but I don't think that will solve the problem.
Best regards,
Chuck Conover
www.TechnicalVideos.net


"Rowland Hills" <ro**********@hotmail.com> wrote in message
news:4d**************************@posting.google.c om...
I have a table which is returning inconsistent results when I query
it!

In query analyzer:

If I do "SELECT * FROM TABLE_NAME" I get no rows returned.

If I do "SELECT COL1, COL2 FROM TABLE_NAME" I get 4 rows returned.

In Enterprise manager:

If I do "return all rows" I get 4 rows returned, and the SQL is listed
as being "SELECT * FROM dbo.TABLE_NAME".

I've tried adding the "dbo." before my table name in QA, but it seems
to make no difference.

I'm using SQL Server 2000, which is apparently 8.00534.

Can anyone help me, or give me ideas about what to check?

Thanks,

Rowland.

Jul 20 '05 #7
Rowland Hills (ro**********@hotmail.com) writes:
I have a table which is returning inconsistent results when I query
it!

In query analyzer:

If I do "SELECT * FROM TABLE_NAME" I get no rows returned.

If I do "SELECT COL1, COL2 FROM TABLE_NAME" I get 4 rows returned.

In Enterprise manager:

If I do "return all rows" I get 4 rows returned, and the SQL is listed
as being "SELECT * FROM dbo.TABLE_NAME".

I've tried adding the "dbo." before my table name in QA, but it seems
to make no difference.


When you tried the query in QA, did you try both text mode and grid mode,
or only one of them? Since you get data in Enterprise Manager, the
data seems to be there, unless you are looking in different databases
or different servers. But one possibility is that there are some strange
character in one column which confuses the output for Query Analyzer.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #8
Well, I've finally solved the problem.

It turned out to be just one column which was causing the problem.
Dropping that column, then recreating it solved the problem. Still
don't know exactly what was wrong, but one of my colleagues uses three
different keyboards (UK, US and Swedish) and suspects that he may have
entered a combination which resulted in an illegal character whilst
defining this column or entering data into it, and that's what caused
the problem.

Anyway, thanks for everyone's helpful suggestions.

Regards,

Rowland.
"Chuck Conover" <cc******@commspeed.net> wrote in message news:<10***************@news.commspeed.net>...
Rowland,
First, only "rebuild" if you are sure the table is corrupted. I have
included how to rebuild below, but I've never seen a table corrupted in SQL
Server 2000, which isn't to say it isn't happening.


<VARIOUS USEFUL REPLIES SNIPPED>
> I have a table which is returning inconsistent results when I query
> it!
>
> In query analyzer:
>
> If I do "SELECT * FROM TABLE_NAME" I get no rows returned.
>
> If I do "SELECT COL1, COL2 FROM TABLE_NAME" I get 4 rows returned.
>
> In Enterprise manager:
>
> If I do "return all rows" I get 4 rows returned, and the SQL is listed
> as being "SELECT * FROM dbo.TABLE_NAME".
>
> I've tried adding the "dbo." before my table name in QA, but it seems
> to make no difference.
>
> I'm using SQL Server 2000, which is apparently 8.00534.
>
> Can anyone help me, or give me ideas about what to check?

Jul 20 '05 #9
mape1082
1 New Member
I had exactly the same problem and I found that the SQL Query Analizer had the Options>Results>Max Chars per Column set to 32. I set it back to 8192 and then it worked fine.

:D
Jul 7 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
16252
by: Dave Wijay | last post by:
Hi Does anybody know how to programmatically select items (rows) of a ListView in C#.NET Thanks in advanc Dave
3
8640
by: gajaya1 | last post by:
I tried similar to sql server to get first 100 rows using "Select top 100 from table1" does not work? Is there another syntax?
2
100335
by: Jim H | last post by:
I am storing incoming data in memory using a DataTable. After I'm done retrieving the data I need to get the distinct rows. I tried using DataTable.Select but that doesn't work. If I have...
0
1777
by: Raj Chudasama | last post by:
how can i select all rows in a datagrid also how can add checkbox to each of my rows in datagrid. I tried to use DataGridColumnStyle but failed try {
2
10682
by: Kevin Hodgson | last post by:
I have a standard .NET Datagrid (Databound to a SQL Dataset), and I need to select all rows of the datagrid when a button is clicked, to allow a user to copy the data, and then paste it into Excel...
5
2312
by: Silvio Matthes | last post by:
Hello, I'm new to the list and did not find a suitable answer to my question so here it is: I try to select the rows of a table where the content of a varchar-column is empty ('') and...
2
23915
by: Ettenurb | last post by:
I was hoping someone has come across this and came up with a solution. We have upgraded our custom software to us Infragistics UltraWinGrid 2006 CLR 2.0. The code below worked with a previous...
2
7695
by: mokazawa1 | last post by:
Hi, I'm using stored procedures in DB2 UDB 8.1.2. In this stored, I execute a select for update command, opening a cursor. Then I update the rows using fetch and current of. The problem is that...
1
3478
by: arockiasamy | last post by:
hi, How to select multiple rows in a table using java script? and that selected rows must be deleted? i have done for single selection. how it can be for multiple? come on help me.. i...
1
1987
by: mbewers1 | last post by:
Hi there, I'm having a strange problem whereby I can execute a select query in Oracle SQL Developer that rerturns some rows but, when this same query is placed into C#, I get no results. I've...
0
6974
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7146
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7183
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6852
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5448
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.