Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data do not display in Query analyzer 4

Status
Not open for further replies.

RSX02

Programmer
May 15, 2003
467
CA
Hi
I have a line of code that I would like to extract data from it. The problem that I have is that is doens't display any record at the bottom of the Query Analyzer. Do I have to put '' or "" for the fields?!

This is my fields type
qty_shipped - decimal (9)
co_num - nvarchar (10)
co_line -smallint (2)
uf_lot - tinyint(1)

SELECT SUM(qty_shipped) from co_ship where co_num = 226 and co_line = 2 and uf_lot = 4
GO

Thanks you very much in advance!
 
You need to use single quotes around character data, so try:

Code:
SELECT SUM(qty_shipped)
FROM co_ship
WHERE co_num = '226'
  AND co_line = 2
  AND uf_lot = 4

--James
 
I tried that
SELECT SUM(qty_shipped) from co_ship where co_num = ' 223' and co_line = 2 and uf_lot = 2
GO

and

SELECT SUM(qty_shipped) from co_ship where co_num = ' 223' and co_line = '2' and uf_lot = '2'
GO

It still doesn't work. The thing that display at the bottom of the screen is one column with the title "No column name" and the value is NULL....

???
 
Are you sure you have rows in there that match all your criteria? Also, why have you got all the spaces in the co_num value?

Does this return any rows?:

Code:
SELECT *
FROM co_ship
WHERE co_num = '226'
  AND co_line = 2
  AND uf_lot = 4

--James
 
Maybe you should modify little bit to
SELECT *
FROM co_ship
WHERE ltrim(rtrim(co_num)) = '226'
AND co_line = 2
AND uf_lot = 4
 
BTW:

The thing that display at the bottom of the screen is one column with the title "No column name" and the value is NULL....

The reason you have the title "No column name" is that you are only requesting an 'aggregate': SUM(qty_shipped). That is not a column, it is a SUM of a column. If you want a 'title' you need to create an ALIAS:

SUM(qty_shipped) AS [Amount Shipped] (square brackets are needed because of the space).


As to why you aren't getting any data returned, as James asked, are you sure there is data that matches your request?

-SQLBill
 
Thanks to all of you for taking time for help me.

I found what was it and you were right. My co_num wasn't co_num = '226' but co_num = '223'.

I'm so sorry to take your time for this. At least be sure that you help me to understand a little bit more SQL as i'm a beginner with that!
Thank you.
a Star for all of you because you really helped me.
 
Glad we could help. Just remember...when you aren't getting the data you expect and you've checked the query, double check the data.

-SQLBill
 
also when i test some query like this, i use LIKE.
I was writing my opinion when RSX02 solve it, but take the hint:

SELECT SUM(qty_shipped) AS [Amount Shipped]
FROM co_ship
WHERE co_num LIKE '%22%'
AND co_line = 2
AND uf_lot = 4

if no data returns, check the query again :)

N: i use the SQLBill hint.
 
Yeah. That's a good hint. I'll keep it in my mind. :)
Thanks also kristjan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top