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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 syntax help needed

Author  Topic 

TJ
Posting Yak Master

201 Posts

Posted - 2002-11-06 : 11:36:02
This query
update irsdata 
set procstat = 'I9'
where ((select charindex('[007]', frmdata, 5)
from tempbatch
where left(frmheader, 3) = 'RET')<> '30401')
and (ntsbatch = 'zzp30401')

is returning the 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.


Will someone please tell me what I'm doing incorrectly and give me pointers on how to correct it? There may be one record that meets the subquery selection criteria, or many.

Thanks!
Teresa

mr_mist
Grunnio

1870 Posts

Posted - 2002-11-06 : 11:42:59
You're attempting to compare

select charindex('[007]', frmdata, 5)
from tempbatch
where left(frmheader, 3) = 'RET'

Against

'30401'

You can't do this because there could be any number of rows that meet that criteria.

What are you trying to do with this query?

Go to Top of Page

TJ
Posting Yak Master

201 Posts

Posted - 2002-11-06 : 11:50:22
quote:
What are you trying to do with this query?


I need all 'RET' records that do not have a '30401' in their frmdata
column to fail. The 'batch' of records may have five records or 50,
with one of them being a 'ret' or many of them being a 'ret'.

Thanks for responding so quickly!
Teresa

Edited by - tj on 11/06/2002 11:51:08
Go to Top of Page

mr_mist
Grunnio

1870 Posts

Posted - 2002-11-06 : 12:09:24
quote:

quote:
What are you trying to do with this query?


I need all 'RET' records that do not have a '30401' in their frmdata
column to fail. The 'batch' of records may have five records or 50,
with one of them being a 'ret' or many of them being a 'ret'.

Thanks for responding so quickly!
Teresa

Edited by - tj on 11/06/2002 11:51:08



Okay but you are updating irsdata and looking at tempbatch, so I'm not sure how these two relate to each other.



Go to Top of Page

mr_mist
Grunnio

1870 Posts

Posted - 2002-11-06 : 12:14:04
You may (at a guess) need something like

UPDATE irsdata
set procstat = 'I9'
from irsdata
left outer join
tempbatch on
something = something
and
left(tempbatch.frmheader, 3) = 'RET'
and
patindex ('30401',frmdata) <> 0
where tempbatch.frmheader is null

Go to Top of Page

TJ
Posting Yak Master

201 Posts

Posted - 2002-11-06 : 12:14:34
quote:
Okay but you are updating irsdata and looking at tempbatch, so I'm not sure how these two relate to each other.



Yes. I'm comparing irsdata to tempbatch and updating irsdata.

Teresa
Go to Top of Page

mr_mist
Grunnio

1870 Posts

Posted - 2002-11-06 : 12:22:08
quote:

quote:
Okay but you are updating irsdata and looking at tempbatch, so I'm not sure how these two relate to each other.



Yes. I'm comparing irsdata to tempbatch and updating irsdata.

Teresa



I'd try out what I posted above as a SELECT to see if you get the rows you are looking for in the results. You just need to figure out what the something = something join is between irsdata and tempbatch, which is the bit I can't tell.

Go to Top of Page

TJ
Posting Yak Master

201 Posts

Posted - 2002-11-06 : 12:42:34
quote:
I'd try out what I posted above as a SELECT to see if you get the rows you are looking for in the results. You just need to figure out what the something = something join is between irsdata and tempbatch, which is the bit I can't tell.


I've been working on this code while we posted back and forth.
update irsdata 
set procstat = 'I9'
from irsdata
inner join
(select irsdataid,ntsbatch, frmheader, substring(frmdata,(charindex('[007]', frmdata)+ 12), 5)as batch
from tempbatch mb
where (left(mb.frmheader, 3) = 'RET' and right(mb.frmheader, 4) = 'pg01'))as mb
on irsdata.ntsbatch = mb.ntsbatch
where (irsdata.ntsbatch = 'zzp30401') and batch <> '30401'

I was finally able to get it work.

Thanks again for your assistance.

Best regards,
Teresa


Edited by - tj on 11/06/2002 12:43:17
Go to Top of Page
   

- Advertisement -