TO ORDER

I have an SQL statement in my C # program that looks like this:

SELECT * FROM XXX.dbo.XXX 
WHERE Source = 'OH'
  AND partnum = '1231202085' 
ORDER BY partnum, Packaging, Quantity

When you run this query in SQL Server Management, the results are ordered as expected. My first 3 results have the same batch and packaging with sizes 32.0, 50.8 and 51.0.

However, when I run a query from my program, the first result is returned with a result of 50.8. The data type Number is decimal (18.9). I tried actuation, this doesn't seem to be a data type problem.

I can’t understand why he gets the average amount.


Thanks guys for the quick answers, but after a little testing, I found my problem in my C # code, and not in sql.

After receiving the query results, I hade:

if (PurchOrder.Read())
    while (PurchOrder.Read())

, , while .

Ive if:

if (PurchOrder.HasRows == true)

.

, . .

-Cody

+3
3

, , , #, sql.

hade:

if (PurchaseOrder.Read()) (PurchaseOrder.Read())

, , while .

Ive if:

if (PurchaseOrder.HasRows == true)

.

, . .

-Cody

0

partnum -, ,

  • partnum

  • - . :

    order by
    RIGHT(REPLICATE('0', 1000) + LTRIM(RTRIM(CAST([field_name] AS VARCHAR(8000)))), 1000)
    

, , .

+1

SQL Server, partnum, - /float-, . , partnum , 10 2.

, , ORDER BY, CONVERT CAST / . CAST/Convert BOL.

:

CREATE TABLE #test
(
 mytest varchar(10)
)

INSERT INTO #test(mytest) VALUES('10')
INSERT INTO #test(mytest) VALUES('1')
INSERT INTO #test(mytest) VALUES('2')
INSERT INTO #test(mytest) VALUES('12')
INSERT INTO #test(mytest) VALUES('20')

SELECT * FROM #test ORDER BY mytest
DROP TABLE #test

. :

SELECT * FROM #test ORDER BY CAST(mytest AS INT)

(#) gridview?

0

All Articles