Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Update Statement
Message
From
09/01/2004 12:59:02
 
 
To
09/01/2004 11:17:05
Alvin Lourdes
Children and Youth Services Cluster
Toronto, Ontario, Canada
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00865465
Message ID:
00865504
Views:
16
a few things missing
1. FROM clause in the subquery
2. something that correlates the subquery to the table being updated, so only one row is returned
3. WHERE clause on the table being updated, so TurnTime values that don't fit the subquery aren't nulled [unless that's the desired behavior]
UPDATE TurnTimeTable
   SET TurnTime = (SELECT (DATECOMPLETE - DATESTART) as 'Turn Time'
   FROM TurnTimeTable t2 --< added FROM
   WHERE EmployeeID NOT LIKE '5%' AND EmployeeID NOT LIKE '9%'
   AND t2.PK = TurnTimeTable.PK --< correlate the subquery
)
WHERE EmployeeID NOT LIKE '5%' AND EmployeeID NOT LIKE '9%' --< update the correct rows
HTH


>Hi,
>
>I'm trying to update a column in a table like this.
>
>UPDATE TurnTimeTable
>SET TurnTime = (SELECT (DATECOMPLETE - DATESTART) as 'Turn Time'
>WHERE EmployeeID NOT LIKE '5%' AND EmployeeID NOT LIKE '9%'
>)
>
>
>Is there a way to do this without getting this error..
>
>Server: Msg 512, Level 16, State 1, Line 1
>Subquery returned more than 1 value.
>This is not permitted when the subquery follows =,
>!=, <, <= , >, >= or when the subquery is used as an expression.
>The statement has been terminated.
>
Insanity: Doing the same thing over and over and expecting different results.
Previous
Reply
Map
View

Click here to load this message in the networking platform