Re: Delete statement with Alias
From: Aaron Bertrand - MVP (aaron_at_TRASHaspfaq.com)
Date: 05/24/04
- Next message: Hilmar: "Nested query"
- Previous message: Aaron Bertrand - MVP: "Re: Nest stored procedure accessing parent objects"
- In reply to: News: "Re: Delete statement with Alias"
- Next in thread: Roji. P. Thomas: "Re: Delete statement with Alias"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 24 May 2004 11:40:44 -0400
Then you must have copied the text wrong, or you have other statements
before or after that are incorrect.
-- Aaron Bertrand SQL Server MVP http://www.aspfaq.com/ "News" <jerry@jacangelo.net> wrote in message news:uaAmPUaQEHA.3012@TK2MSFTNGP09.phx.gbl... > Thanks for the quick reply, but it does NOT work. I get: Incorrect syntax > near '65'. error message. > > > "Gregory A. Larsen" <greg.larsen@netzero.com> wrote in message > news:u7yj3PaQEHA.368@TK2MSFTNGP09.phx.gbl... > > Try this (untested) > > > > delete from civ > > where DATEPART(year, GETDATE()) - LEFT(dob, 4) > 65 > > > > > > -- > > > > -------------------------------------------------------------------------- > -- > > -------------------------------------------------------------------------- > -- > > ---- > > > > Need SQL Server Examples check out my website at > > http://www.geocities.com/sqlserverexamples > > "News" <jerry@jacangelo.net> wrote in message > > news:e53$NLaQEHA.556@tk2msftngp13.phx.gbl... > > > I'm trying to delete records from a table for all people over the age of > > 65. > > > I have to derive the age based off of todays date - the year from the > dob > > > column. dob column is char(8), not DATETIME. I can get to a point with > > the > > > select statement to show me all records in the table, but I can't apply > > > criteria (where clause) without getting errors in ref to alias column > > name. > > > The statement below works: > > > > > > SELECT ssn, DATEPART(year, GETDATE()) - LEFT(dob, 4) AS [age] > > > FROM dbo.civ > > > > > > When I add a where clause I get an 'Invalid column name 'age'.' error > > > > > > This is as afar as I got with the delete statement, but it does not > work: > > > > > > delete from civ > > > where ( > > > SELECT DATEPART(year, GETDATE()) - LEFT(dob, 4) AS [age] > > > FROM dbo.civ where [age] > 65) > > > > > > Thanks > > > > > > > > > > > >
- Next message: Hilmar: "Nested query"
- Previous message: Aaron Bertrand - MVP: "Re: Nest stored procedure accessing parent objects"
- In reply to: News: "Re: Delete statement with Alias"
- Next in thread: Roji. P. Thomas: "Re: Delete statement with Alias"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|