Re: Delete statement with Alias

From: Aaron Bertrand - MVP (aaron_at_TRASHaspfaq.com)
Date: 05/24/04


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
> > >
> > >
> >
> >
>
>


Relevant Pages

  • Re: Inconsistent negative numerical values in SQL2K database table
    ... fix of 1*value and it works as you mentioned. ... To answer your question about copying between SQL Server instances I don't ... will copy between SQL Server tables carrying with it the incorrect sign bit. ... Since the cube is partitioned some of the partitions are ...
    (microsoft.public.sqlserver.server)
  • Re: security question
    ... > I have a stand alone laptop with 2 instances of SQL Server on it. ... > Then try to park it in a role dbo, ddladmin, etc. ... > new password it tells me the password is incorrect. ...
    (microsoft.public.sqlserver.security)
  • Re: Red X on publication and distribution agent
    ... > There is a table in the tempdb database that contains the status of the ... Tempdb is recreated whenever SQL Server ... Manually delete the row with the incorrect status. ...
    (microsoft.public.sqlserver.replication)
  • Re: Server: Msg 7619: Cannot build FTcatalog
    ... recommend that you place a support call to Microsoft's PSS SQL Server ... If you do open a support case with Microsoft PSS SQL Server support and they ... The parameter is incorrect. ...
    (microsoft.public.sqlserver.fulltext)