Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here I am having the code.
It showing the entire record i need to show only one record with bill number.
In my case bill number 13 showing 3 results i need only last record with this id.

SQL
create procedure [dbo].[bindgv]
as
select [Bill Number],Date,Name,Particulars,Amount from Sontra_task
order by Date desc


Bill.No | Date | Name | Part. | Amount
17 | 2013-12-25 | Amar | FFR2 | 5788
12 | 2013-12-12 | ashraf | FFR2 | 566
2 | 2013-12-10 | Amrita | FF$ | 5454654654
13 | 12/28/2013 | Dawood | b | 2000
13 | 12/28/2013 | Dawood | c | 3000
13 | 12/28/2013 | Dawood | a | 1000
6 | 12/14/2013 | Komal FFR1 | 1500

i want to show the result like the following ...

17 2013-12-25 Amar FFR2 5788
12 2013-12-12 ashraf FFR2 566
2 2013-12-10 Amrita FF$ 5454654654
13 12/28/2013 Dawood b 2000
6 12/14/2013 Komal FFR1 1500

Could anybody suggest me for a perfect query.
Thank you
Posted
Updated 27-Jan-14 23:33pm
v2

plz check the following link
[^]
 
Share this answer
 
Comments
Md.Ashraf Ali 28-Jan-14 6:01am    
Hey Thank you bro it works but little problem.
It returns multiple record when i write the following query
SELECT DISTINCT([Bill Number]) as BillNumber,Name,Date,Amount FROM Sontra_task

It works fine when i exclude Amount column ....
ok dear try this one if it works

select distinct [Bill Number] from (select top 100 percent count(*) from Sontra_task order by [Amount])
 
Share this answer
 
Comments
Md.Ashraf Ali 28-Jan-14 6:25am    
Same error dude....i know it will work but dunno what is happening ...please try once
DotnetCoders001 28-Jan-14 6:30am    
Hi,

Can you paste the exat query you are using along with the exact table column names and table name.
Md.Ashraf Ali 28-Jan-14 6:39am    
I am using your query now...
select distinct [Bill Number] from (select top 100 percent count(*) from Sontra_task order by [Amount]

Sontra_task

[Bill Number] float
Date nvarchar(MAX)
Name nvarchar(MAX)
Particulars nvarchar(MAX)
Amount float
Total float
[Amount in words] nvarchar(MAX)
Address nvarchar(MAX)
City nvarchar(MAX)
DotnetCoders001 30-Jan-14 3:16am    
Hi,
did you find a solution or still stuck?
DotnetCoders001 31-Jan-14 5:09am    
Heloz did you find a solution?
If u want to fetch last record i.e. the one one having amount as 1000 use the following query :-

select distinct [Bill Number] from (select * from Sontra_task order by [Amount])
 
Share this answer
 
Comments
Md.Ashraf Ali 28-Jan-14 5:39am    
It showing the following error.

The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.
Hi,
Try this

select distinct [Bill Number] from (SELECT TOP 100 PERCENT from Sontra_task order by [Amount])

let me know if it works !
 
Share this answer
 
Comments
Md.Ashraf Ali 28-Jan-14 6:06am    
Now it showing ...
Incorrect syntax near the keyword 'from'
I missed the asterix in syntax

select distinct [Bill Number] from (select top 100 percent * from Sontra_task order by [Amount])


Now check and let me knw !
 
Share this answer
 
Comments
Md.Ashraf Ali 28-Jan-14 6:16am    
Incorrect syntax near ')'.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900