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 |
|
callawayx14
Yak Posting Veteran
73 Posts |
Posted - 2007-03-01 : 09:46:30
|
| Hello All, This is my first post. I'm having a problem with the query below. The 'No. or Days' criteria is not working. I've tried creating Variable Tables and #tables (which work) but are not an option for me at this point....SELECT table_part_num.x_company AS Company, table_part_num.part_number AS [Part Name], table_site_part.serial_no AS [Serial Number], table_site_part.x_bar_code AS Barcode, table_site.site_id AS [Site/Terr], ( Select (DATEDIFF(d, MAX(table_act_entry.entry_time), GETDATE()))) AS [No. of Days] FROM table_part_num WITH (NOLOCK) INNER JOIN table_mod_level WITH (NOLOCK) INNER JOIN table_site WITH (NOLOCK) INNER JOIN table_act_entry WITH (NOLOCK) INNER JOIN table_site_part WITH (NOLOCK) ON table_act_entry.act_entry2site_part = table_site_part.objid ON table_site.objid = table_site_part.site_part2site ON table_mod_level.objid = table_site_part.site_part2part_info ON table_part_num.objid = table_mod_level.part_info2part_num WHERE (table_part_num.active = 'Active') AND (table_act_entry.act_code = '3700') AND table_site.site_id <> 'Decomissioned' AND ('No. of Days' >= '878')GROUP BY table_part_num.x_company, table_part_num.part_number, table_site_part.serial_no, table_site_part.x_bar_code, table_site.site_id |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-03-01 : 09:48:24
|
You can't add Alias as a part of condition. You will have to repeat the expression in the WHERE clause again.AND (DATEDIFF(d, MAX(table_act_entry.entry_time), GETDATE()))) >= 878 Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-01 : 09:49:26
|
quote: ('No. of Days' >= '878')
?why are you comparing a string with another ? Oh did not see the column alias there  KH |
 |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2007-03-01 : 10:41:58
|
| "You can't add Alias as a part of condition. You will have to repeat the expression in the WHERE clause again."......or put this query into a subquery/derived table and then add a "WHERE ('No. of Days' >= '878'))" clause to the execution of the subquery/derived table. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-01 : 12:15:21
|
| ? '9' >= '87723837623'TRUEPeter LarssonHelsingborg, Sweden |
 |
|
|
callawayx14
Yak Posting Veteran
73 Posts |
Posted - 2007-03-01 : 14:43:40
|
harshThank you very much. I added your line to the HAVING clause and it worked!!!!! I'm sure you'll hear from me againI really appreciate everyones help. !!!!!!! |
 |
|
|
|
|
|
|
|