Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SORT in Squery

Author  Topic 

sureshprpt
Starting Member

33 Posts

Posted - 2011-11-03 : 13:38:01
Hello ,

PLease help me to write the squery to download the data from the data as per my requirement.

The sample data currently in table
Code --- Bil----Value---- ID---- LIne------ Asso.Line
F1 ---- F2 ---- F3 ---- F4 ---- F5 ----- F6
XXX ----Bil:1-- 1000 ---- 1 ---- 19 ----- 22
XXX ----Bil:2---2000 ---- 1 ---- 20 ----- 24
ED ---- 10% --100 ---- 1 ---- 21 ----- 19
SHEC-----2% -- 10 ----- 1 ---- 22 ----- 19
ED ---- 10% --200 ---- 1 ---- 21 ----- 20
SHEC-----2% -- 20 ----- 1 ---- 22 ----- 20

My requirement to download the report in the below format

ode --- Bil----Value---- ID---- LIne------ Asso.Line
F1 ---- F2 ---- F3 ---- F4 ---- F5 ----- F6
XXX ----Bil:1-- 1000 ---- 1 ---- 19 ----- 22
ED ---- 10% --100 ---- 1 ---- 21 ----- 19
SHEC-----2% -- 10 ----- 1 ---- 22 ----- 19
XXX ----Bil:2---2000 ---- 1 ---- 20 ----- 24
ED ---- 10% --200 ---- 1 ---- 21 ----- 20
SHEC-----2% -- 20 ----- 1 ---- 22 ----- 20

I want the report to download the report related excise value below to the basic price.

The key field is Line & Asso. Line.

Thanks
Suresh

Thanks & Regards
Suresh

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-03 : 13:53:44
sorry didnt understand on what basis you want to sort

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sureshprpt
Starting Member

33 Posts

Posted - 2011-11-03 : 23:20:54
quote:
Originally posted by visakh16

sorry didnt understand on what basis you want to sort

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





Can you send you email ID. i send the attachment for clear report.

Thanks
Suresh

Thanks & Regards
Suresh
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-11-04 : 00:40:40
please explain what is the sorting sequence that you need


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-04 : 04:28:12
quote:
Originally posted by sureshprpt

quote:
Originally posted by visakh16

sorry didnt understand on what basis you want to sort

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





Can you send you email ID. i send the attachment for clear report.

Thanks
Suresh

Thanks & Regards
Suresh


please post attachment in some shared server and give path here

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-11-04 : 05:58:29
[code]DECLARE @Sample TABLE
(
Code VARCHAR(10),
Bil VARCHAR(10),
Value INT,
ID INT,
Line INT,
Asso INT
)

INSERT @Sample
VALUES ('XXX', 'Bil:1', 1000, 1, 19, 22),
('XXX', 'Bil:2', 2000, 1, 20, 24),
('ED', '10%', 100, 1, 21, 19),
('SHEC', '2%', 10, 1, 22, 19),
('ED', '10%', 200, 1, 21, 20),
('SHEC', '2%', 20, 1, 22, 20)

-- Solution by SwePeso
SELECT *
FROM @Sample
ORDER BY CASE
WHEN Code = 'XXX' THEN Line
ELSE Asso
END,
Line[/code]


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -