Click here to Skip to main content
11,717,960 members (77,601 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL queries
My query is -:
select salesDetails.bill_no,custDetails.custName,custDetails.custAdd from salesDetails,custDetails where custDetails.custID=(select salesDetails.custID from salesDetails where slsDate between #" + DTP1.Value.Date.ToShortDateString() + "# and #" +DTP2.Value.Date.ToShortDateString() + "#)

when i run this query It's give an error "At most one record can be returned by this subquery".
I want to get all the bill_no between given date and get that customer details from custDetails table specific custID...

thanks in advance....
Posted 25-Feb-13 7:04am
Edited 25-Feb-13 7:05am
v2
Comments
richcb at 25-Feb-13 13:08pm
   
You are not joining your tables you are selecting from.
Jayanta Chatterjee at 25-Feb-13 13:14pm
   
Ooops!! I missed That....
Thanks....

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You could change from WHERE custID = to custID IN
select salesDetails.bill_no,custDetails.custName,custDetails.custAdd from salesDetails,custDetails where custDetails.custID IN (select salesDetails.custID from salesDetails where slsDate between #" + DTP1.Value.Date.ToShortDateString() + "# and #" +DTP2.Value.Date.ToShortDateString() + "#)
  Permalink  
Comments
Jayanta Chatterjee at 25-Feb-13 13:25pm
   
Sir it returns the same row two times...
ryanb31 at 25-Feb-13 13:43pm
   
Oh, sorry, I didn't look closely at your SQL. I was only looking at your question. You are doing a cross join by having "FROM salesDetails, custDetails." What you really need to do, now that I looked closer, is to do a join and not a subquery. See if this works.

SELECT s.bill_no, c.custName, c.custAdd
FROM salesDetails s
INNER JOIN custDetails c ON s.custID = c.custID
WHERE s.slsDate BETWEEN date1 AND date2
Jayanta Chatterjee at 25-Feb-13 13:48pm
   
Thankssss a Lottttt Sir... :-)
ryanb31 at 25-Feb-13 13:51pm
   
You're welcome. Sorry I missed that the first time.
Jayanta Chatterjee at 25-Feb-13 13:56pm
   
It's Okay..
Sir, You solve that Problem....
Thanks Again... :-)

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 849
1 OriginalGriff 215
2 F-ES Sitecore 210
3 Maciej Los 140
4 Jochen Arndt 120
0 Sergey Alexandrovich Kryukov 1,494
1 OriginalGriff 535
2 Maciej Los 529
3 Richard MacCutchan 440
4 CHill60 415


Advertise | Privacy | Mobile
Web02 | 2.8.150901.1 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100