473,653 Members | 2,990 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error on Returning More than 1 Value

3 New Member
Hi,

I'm having a problem with the following trigger:

CREATE TRIGGER tr_FamID
ON dbo.myFirstTbl
FOR INSERT
AS
DECLARE @address2 VARCHAR (50)
DECLARE @compareFamID INT

SELECT @address2 = Address FROM inserted
SELECT @compareFamID = FamID FROM inserted

IF @address2 = ' '
BEGIN
DROP TRIGGER tr_famID
END

IF @address2 != ' '
BEGIN
DECLARE @newRec int
DECLARE @newFam int
DECLARE @newLast VARCHAR(50)
DECLARE @newFirst VARCHAR(50)
DECLARE @newAddress VARCHAR(50)

SET @newRec = (SELECT RecID FROM myFirstTbl)
SET @newFam = (SELECT FamID FROM myFirstTbl)
SET @newLast = (SELECT LastName FROM myFirstTbl)
SET @newFirst = (SELECT FirstName FROM myFirstTbl)
SET @newAddress = (SELECT Address FROM myFirstTbl)

INSERT INTO dbName.dbo.mySe condTbl (FamID, LastName,
FirstName, Address) SELECT @newFam, @newLast, @newFirst,
@newAddress FROM myFirstTbl WHERE @newFam = @compareFamID

DELETE FROM myFirstTbl WHERE FamID = @compareFamID
END

The error that's giving me is that the subquery is returning more than one value...and I guess sql doesn't like that. What I want is to INSERT all of the records on the myFirstTbl table that have the same FamID (for example...WHERE FamID = '2') into the mySecondTbl table which is located in another database separate from the myFirstTbl table. After that's done, I would like to delete the records from the myFirstTbl table. So, because of this, I think it makes sense for the subquery to return more than 1 value, but it's erroring out. The information will be entered into the database using a Visual Basic.Net application (Visual Studio 2005). I would also like to add that i'm new to triggers so if i'm doing something that I should't be doing or that could hurt performance, please tell me.

I would really appreciate your help.
Aug 7 '07 #1
3 1236
azimmer
200 Recognized Expert New Member
Hi,
...
INSERT INTO dbName.dbo.mySe condTbl (FamID, LastName,
FirstName, Address) SELECT @newFam, @newLast, @newFirst,
@newAddress FROM myFirstTbl WHERE @newFam = @compareFamID
...

The error that's giving me is that the subquery is returning more than one value...and I guess sql doesn't like that.

...
I think the problem is that the inner SELECT is a bit malformed. I believe you meant to select columns from myFirstTable in which case you column names of myFirstTable in the select list not local variables (i.e. surely no @'s in it). It also applies to the left part of the WHERE clause, like this:

Expand|Select|Wrap|Line Numbers
  1. NSERT INTO dbName.dbo.mySecondTbl (FamID, LastName,
  2. FirstName, Address) SELECT myFirstTbl.FamID, myFirstTbl.LastName,
  3. myFirstTbl.FirstName, myFirstTbl.Address FROM myFirstTbl WHERE myFirstTbl.FamID = @compareFamID
  4.  
It is also an interesting action to drop the trigger from within the trigger. While to my recon it is OK for the SQL Server (syntax OK), I wouldn't use it myself. (The trigger may mysteriuosly disappear with an insert... If you do want to get rid of it, do it explicitly from the application code.)
Aug 8 '07 #2
yanksRoll
3 New Member
thanks for your help man, it was very helpful. You were right, I didn't needed the variables. It worked by replacing the variables with the actual column names from the table.

As for DROPING the trigger, you were right again...it was a bad idea to include it.
Aug 8 '07 #3
ck9663
2,878 Recognized Expert Specialist
thanks for your help man, it was very helpful. You were right, I didn't needed the variables. It worked by replacing the variables with the actual column names from the table.

As for DROPING the trigger, you were right again...it was a bad idea to include it.

or access the inserted table instead...trigg er runs right after the insert, but it will not immediately commit the transactions... it will insert a similar record first on the inserted table, before it actually insert it to your myFirstTable... that's the best way to access the record that you are trying to insert..
Aug 9 '07 #4

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

Similar topics

9
11906
by: mjm | last post by:
Folks, Stroustrup indicates that returning by value can be faster than returning by reference but gives no details as to the size of the returned object up to which this holds. My question is up to which size m would you expect vector<double> returns_by_value() {
6
4739
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
16
7214
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
3
2646
by: Alberto Giménez | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi there! I'm doing some homework (almost finished), but now i'm reconsidering a design decission I made at the beginning. This is about error handling in functions. I have my functions returning 0 if OK, and an "enum" error indicating the type of error. A typical pseudo-code is like:
4
3138
by: jt | last post by:
I'm getting a compiler error: warning C4172: returning address of local variable or temporary Here is the function that I have giving this error: I'm returning a temporary char string and its not liking it. How can I fix this? char *dequeue(struct node **first) { char temp;
11
4829
by: suzy | last post by:
i am trying to write aspx login system and the login process requires a validity check of username and password. i have been told that raising exception is costly, but i want a custom error message to be displayed depending on what error occurred (let's say: invalid username, invalid password, password must contain 5 or more characters, etc). at the moment, my login method is returning true/false depending on whether the login was...
7
5002
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying. I created the websetup and built the MSI, have the bundled version. Copied to webserver and ran Websetup.msi. Said I had to remove old version, which I did, then reran WebSetup.msi and keeps giving me this error. "The installer was interrupted...
9
2944
by: Ratfish | last post by:
I'm getting a "2014:: Commands out of sync; you can't run this command now" error on a php page when I try to call a second stored procedure against a MySQL db. Does anyone know why I might be getting this error? The error doesn't occur on my development box where I use the 'root' db user, but does occur in production where I'm using a non- root user record to establish a connection. I'm essentially opening a connection at the top of...
5
3018
by: Conrad Lender | last post by:
I'd like to hear your opinions about the appropriate way to deal with non-critical errors that can occur in user-defined functions. For example, an application chooses to extend String.prototype with a format() method similar to sprintf(). Several formats (%d, %f, etc) are supported, but %z would be invalid. During the parsing of the format string, the function encounters an invalid format which (most likely) was caused by a programmer...
0
8370
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
8283
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
8811
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8470
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
7302
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...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4147
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1591
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.