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 |
evanburen
Posting Yak Master
167 Posts |
Posted - 2014-11-07 : 14:56:59
|
HiI'm struggling with this query and looking for help. I have a list of companies in table named 'PCAs' and another table named 'PCACalls_Assignments'. I want the query results to drop off the name of the companies (PCA) for whatever ReviewDate I pass to it. For example, if my ReviewDate parameter is '11/14/2014', then the results would contain every company in the PCAs table except for PCAID 1 and PCAID 2 because they already have records in the PCACalls_Assignments table. This query doesn't work because if I pass '11/14/2014' to it PCAID 1 will still show up in the results because there is another record in the Assignments table with a ReviewDate = '10/22/2014'SELECT PCAs.PCAID ,PCA FROM PCACalls_Assignments RIGHT OUTER JOIN PCAs ON PCACalls_Assignments.PCAID = PCAs.PCAID WHERE (CONVERT(VARCHAR(10), PCACalls_Assignments.ReviewDate, 110) <> @ReviewDate) ORDER BY PCATable: PCAsPCAID PCA1 Company12 Company23 Company34 Company45 Company56 Company67 Company78 Company89 Company910 Company10Table: PCACalls_AssignmentsPCAID ReviewDate1 11/14/2014 0:002 11/14/2014 0:003 10/22/2015 0:003 11/1/2014 0:004 10/22/2015 0:001 10/22/2014 0:007 10/22/2014 0:00 |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-11-07 : 15:07:21
|
What is the format of @ReviewDate? e.g. If I just do this:SELECT (CONVERT(VARCHAR(10), GETDATE(), 110)) AS Varchar_Date I get:quote: Varchar_Date11-07-2014
Note the hyphens in the date. Does that match the format of your variable @ReviewDate? |
|
|
evanburen
Posting Yak Master
167 Posts |
Posted - 2014-11-07 : 15:36:33
|
HiMy date format is mm/dd/yyyy |
|
|
ScottPletcher
Aged Yak Warrior
550 Posts |
Posted - 2014-11-07 : 17:19:11
|
Don't use functions on any column if you can avoid it, and never convert a date/datetime column to char to do comparisons.WHERE PCACalls_Assignments.ReviewDate >= @ReviewDate AND PCACalls_Assignments.ReviewDate < DATEADD(DAY, 1, @ReviewDate) |
|
|
|
|
|