473,669 Members | 2,453 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

While Loop

10 New Member
Hi All

I need some help again. I am using a instead of insert to update and insert records. When I am doing multiple records i get am error

Subquery returned more than 1 value. This is not permitted when the
subquery follows =, !=, <, <=, <, >= or when the subquery is used as an
expression.

So i am thinking of using a cursor to do this.
Am i right in wanting to use a cursor or is there some other way in achieving this

I was using a table variable in the stored procedure

the insert statement in the store procedure looks like this

INSERT Customer
Select * FROM @Table
this then fires the instead on insert trigger

thanks in advance
Mar 20 '08 #1
2 1830
ck9663
2,878 Recognized Expert Specialist
Hi All

I need some help again. I am using a instead of insert to update and insert records. When I am doing multiple records i get am error

Subquery returned more than 1 value. This is not permitted when the
subquery follows =, !=, <, <=, <, >= or when the subquery is used as an
expression.

So i am thinking of using a cursor to do this.
Am i right in wanting to use a cursor or is there some other way in achieving this

I was using a table variable in the stored procedure

the insert statement in the store procedure looks like this

INSERT Customer
Select * FROM @Table
this then fires the instead on insert trigger

thanks in advance

The error you're getting came from one of your subquery. This happens when you're expecting a subquery to return a single value but instead returns two or more. Since you did not post your code, I can't say if it's inside the trigger or outside.

-- CK
Mar 20 '08 #2
allik7
10 New Member
This is the code in the instead of insert trigger

ALTER TRIGGER [Cust_Audit] ON [dbo].[Customer]
INSTEAD OF INSERT
AS

DECLARE @CustNum int
DECLARE @CustomerCode INT,@CustomerId entificationTyp e INT
DECLARE @CustomerIdenti ficationGroupCo de CHAR(50),@Docum entNumber CHAR(50)
DECLARE @FirstName CHAR(50),@LastN ame CHAR(50),@Middl eName CHAR(50)
DECLARE @CustomerName CHAR(50)
BEGIN
SET @CustomerCode = (select customercode from inserted)
SET @CustomerIdenti ficationType = (select CustomerIdentif icationType from inserted)
SET @CustomerIdenti ficationGroupCo de = (select CustomerIdentif icationGroupCod e from inserted)
SET @DocumentNumber = (select DocumentNumber from inserted)
SET @FirstName = (select FirstName from inserted)
SET @LastName = (select LastName from inserted)
SET @MiddleName = (select MiddleName from inserted)
SET @CustomerName =(select CustomerName from inserted)
END
Set @CustNum =(Select top 1 cc.CustomerCode From Customer cc, inserted i WHERE cc.CustomerCode = i.CustomerCode)


--set nocount off

If ISNULL(@CustNum ,'')=''

BEGIN
INSERT INTO CUSTOMER(Custom erCode,Customer IdentificationT ype ,
CustomerIdentif icationGroupCod e,DocumentNumbe r,
FirstName,LastN ame,MiddleName,
CustomerName)
values(@Custome rCode,@Customer IdentificationT ype,@CustomerId entificationGro upCode,@Documen tNumber,
@FirstName,@Las tName,@MiddleNa me,@CustomerNam e)
end

SELECT CustomerCode FROM Customer where CustomerCode = @CustomerCode
INSERT INTO
SysDatabase_Tra nsactions( TableName,Opera tion,TransferDa teTime)
Select b.CustomerCode, 'Customer','I', Getdate()
From Inserted b
--END
ELSE
BEGIN
UPDATE Customer
SET CustomerCode = @CustomerCode,C ustomerIdentifi cationType = @CustomerIdenti ficationType,
CustomerIdentif icationGroupCod e = @CustomerIdenti ficationGroupCo de,
DocumentNumber = @DocumentNumber ,FirstName=@Fir stName,LastName =@LastName,
MiddleName=@Mid dleName,Custome rName=@Customer Name WHERE CustomerCode = @CustomerCode
--END

SELECT CustomerCode FROM Customer where CustomerCode = @CustNum
IF @@ROWCOUNT <> 0
INSERT INTO
SysDatabase_Tra nsactions( Record_Id,Table Name,Operation, TransferDateTim e)
Select b.CustomerCode, 'Customer','U', Getdate()
From Inserted b
END





GO
SET QUOTED_IDENTIFI ER OFF
GO
SET ANSI_NULLS ON
GO
Mar 21 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

14
15225
by: jsaul | last post by:
Hi there, wouldn't it be useful to have a 'while' conditional in addition to 'if' in list comprehensions? foo = for i in bar: if len(i) == 0: break foo.append(i)
33
3833
by: Diez B. Roggisch | last post by:
Hi, today I rummaged through the language spec to see whats in the for ... else: for me. I was sort of disappointed to learn that the else clauses simply gets executed after the loop-body - regardless of the loop beeing entered or not. So where is an actual use case for that feature? I imagined that the else-clause would only be executed if the loop body
9
9182
by: Ben | last post by:
I have two 'Do While Not' statements, that are getting information from the same recordset. If I comment out the first one I can get the results for the second one, and vice-versa. Why is this happening? Is it because it's already at the EOF? If so how do I get it back to the BOF for the 2nd 'Do While Not' statement? '---------------------------------------- 'Create an ADO recordset object Set rs_Report =...
7
3204
by: Mahesh Kumar Reddy.R | last post by:
Hi Can any body resolve this.. In what cases one of the loop constructs better than other interms of speed , space and any other (redability). thanks mahesh
36
2797
by: invni | last post by:
I have a nested while. How do I go from the inner while to the beginning of the outer while? Can this be done without using goto? while_1() { some codes here while_2() { if true go to the beginning of while_1 }
6
71965
by: John Pass | last post by:
What is the difference between a While and Do While/Loop repetition structure. If they is no difference (as it seems) why do both exist?
12
1972
by: Howard | last post by:
Hello everyone (total VB.NET beginner here), I'm reading the "SAMS Teach Yourself VB.NET In 21 Days" book, and came across an exercise that I can't get to work. The exercise asks that you create a game that makes the user guess a number from 1-100, and you tell the user "lower" or "higher" as they input their guesses, until they guess the correct number, at which point you then tell the user "Correct". I tried using the While Loop, and...
16
3517
by: Claudio Grondi | last post by:
Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of instructions which can sure be optimized away is the check for the break condition, at least within the time where it is known that the loop will not reach it. Any idea how to write such a loop? e.g.
10
2316
by: rohitjogya | last post by:
Can anyone tell me the difference bet for loop and while loop execution? ____________________ for (i=0 ; i<10 ; i++) ; /* Do nothing*/ print i; ___________________ i=0;
5
5047
by: Alex | last post by:
Hi I just want to clear something up in my head with while loops and exceptions. I'm sure this will probably be a no brainer for most. Check this simple pseudo-code out (vb.net): ------------------------------ try
0
8466
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8384
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8810
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8590
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8659
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7410
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5683
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4387
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1790
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.