Click here to Skip to main content
15,914,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to fetch dishes name with count their quantity b/two dates. this is my code--

SELECT COUNT(Qty) FROM (SELECT Dishes FROM Temp_Dishes where Dates='" + dd.ToString("dd-MM-yyyy") + "' GROUP BY Dishes) p

the error msg is-"No value given for one or more required parameters."
Posted
Comments
thatraja 11-Oct-13 4:57am    
Your query is wrong, include the table srtuctures & sample data in your question.

You've mentioned your tables ,
but i think , you should fetch Qty in your inner query , if you want to count the qty field
you should fetch it in the inner query !
 
Share this answer
 
Comments
Aniket Yadav 11-Oct-13 5:02am    
Provide Sample data.
Try the query similar to this. Hope it helps.

SQL
SELECT Dishes,SUM(qty) FROM Temp_Dishes where Dates between @startdate and @enddate GROUP BY Dishes
 
Share this answer
 
v2
Comments
Jyoti Pandey 12-Oct-13 2:32am    
Thanks,its working now...!!
ArunRajendra 16-Oct-13 23:49pm    
Hi, Please mark the solution as answered so that it will help other in future. Rate the answer if you want to where 5 being the highest.

Thanks
Arun
instead of
C#
dd.ToString("dd-MM-yyyy") 
write
C#
dd.ToString("yyyy-MM-dd") 

Happy Coding!
:)
 
Share this answer
 
There are a few things wrong here.

1.
First, if you can, use parametrized queries instead of concatenating strings

2.
this part:
C#
Dates='" + dd.ToString("dd-MM-yyyy")

is not guaranteed to work. Or pass a date object through parametrized queries or parse the date of the column to a string with the same format you pass the dd value. In this case dd-MM-yyyy.

3.
I'm not sure you need an inner and outer query and I don't believe this will work. The outer query does not know "Qty".
Doesn't this work?
C#
SELECT Count(Dishes) as qty FROM Temp_Dishes where Dates=@startdate GROUP BY Dishes


Hope this helps.
 
Share this answer
 

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