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.
| Author |
Topic |
|
imughal
Posting Yak Master
192 Posts |
Posted - 2004-08-18 : 05:09:51
|
| i have 2 tables processedfiles and unprocessedfile. Both table contains clientid, filename,uploaddate .i have to list all upload date with their respective clients in given month and year.on the basis of that recoed i have to list the unprocessed file date of espective client.The structure of the data isclientid Unprocessedfile processedfile *** 30/7 [dd/mm] 2/8 5/8 5/8 6/8 8/8 18/8 20/8first i have to list all clients from processed file then check unprocessed file data which is less then processed file.i have develop a stored procedure which returns all processedfile data in correct order but when i apply sub query for unprocessed file data it return error. Subquery returned more than 1 value.The store procedure is here.Declare @monthno intDeclare @year intset @monthno=8Set @year=2004select caclientsloginid,upload_date as 'Processed Send', noofmonths as 'No. of Months',(select upload_datefrom fileinfo as Bwhere right(rtrim(filename),3)= 'zip' andfilename <> 'NULL' andb.caclientsloginid=c.caclientsloginid and b.upload_date < c.upload_date andmonth(upload_date) = @monthno andyear(upload_date) = @year)from backpdfinfo as c where filename <> 'NULL' andmonth(upload_date) = @monthno andyear(upload_date) = @year order by caclientsloginidwhen i try sub query seprated with fixed value its return only 1 rec.select upload_datefrom fileinfo as Bwhere right(rtrim(filename),3)= 'zip' andfilename <> 'NULL' andb.caclientsloginid=3773 and b.upload_date < '2004-08-07' andmonth(upload_date) = 8 andyear(upload_date) = 2004 Kindly tell me how to solve the sub query result. any idea.thx iffi |
|
|
gates_micro
Starting Member
29 Posts |
Posted - 2004-08-18 : 05:36:54
|
| SELECT DISTINCT A.CLIENTID,A.FILENAME,A.UPLOADATE FROM(SELECT CLIENTID,FILENAME,UPLOADATE FROM UNPROCESSEDFILE)A,(SELECT CLIENTID,UPLOADATE FROM PROCESSEDFILE) BWHERE A.UPLOADATE<B.UPLOADATEAND A.CLIENTID=B.CLIENTID |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-08-18 : 08:28:45
|
Too idenitify your problem, run this:The subquery column should show you where you have multiple records.Don't forget that the way you have this set, the conditions in the sub that reference c.caclientsloginid and c.upload_date will change as those values change. Most likely the source of your problem.Try out gates solution, I'm kinda confused on what you are trying to do.Declare @monthno intDeclare @year intset @monthno=8Set @year=2004select caclientsloginid, upload_date as 'Processed Send', noofmonths as 'No. of Months', ( select count(*)--upload_date from fileinfo as B where right(rtrim(filename),3)= 'zip' and filename <> 'NULL' and b.caclientsloginid=c.caclientsloginid and b.upload_date < c.upload_date and month(upload_date) = @monthno and year(upload_date) = @year ) as SubQueryfrom backpdfinfo as c where filename <> 'NULL' andmonth(upload_date) = @monthno andyear(upload_date) = @year order by caclientsloginid Corey |
 |
|
|
|
|
|
|
|