Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Creating a useable trigger.
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

2 Posts

Posted - 10/11/2012 :  07:40:13  Show Profile  Reply with Quote
Hi. I am pretty new to this sql server 2012 programming and have a difficult task in school wich i can't seem to figure out. So I now ask for your help.
The task is as follows:
Create a AFTER INSERT trigger for the table Sokande that verifies the new row(s) postalcode (postNr) and city is correct. This is done by finding the postalcode and making sure the city is correct. If the postalcode isn't found or the city doesn't match, the new row(s) should be deleted from the Sokande table by the trigger.

So thats the task I've been working on for two days. I hope you understand and I hope any of you can help me in any way possible.

Thanks, Borgen313.

Edited by - Borgen313 on 10/11/2012 07:45:33

Flowing Fount of Yak Knowledge

5155 Posts

Posted - 10/11/2012 :  07:46:24  Show Profile  Reply with Quote
Usually people on the forum are reluctant to post answers to school-related work for fear that they may be doing a disservice rather than helping. If you post what you have tried so far, I am sure many people on the forum would be very glad to help.

Take a look at this page, write something that you think is right, even if it doesn't do everything you want to and post the code:
Go to Top of Page

Starting Member

2 Posts

Posted - 10/11/2012 :  08:01:00  Show Profile  Reply with Quote
Okey good to know. But no need to worry about that, everyone doing the task right now is just about to give up and this is our last hope.

This is what we have tried so far:

CREATE TRIGGER dbo.check_delete_postNr_ort ON dbo.Sokande

DECLARE @isokarNr numeric
DECLARE @ipostNr char
DECLARE @iort varchar
DECLARE @ppostNr char
DECLARE @port varchar

SELECT @isokarNr = sokarNr, @ipostNr = postNr, @iort = ort

SELECT @ppostNr = postNr, @port = ort
FROM Postnummer
WHERE postNr = @ipostNr
ort = @iort

IF @ipostNr <> @ppostNr OR @iort <> @port
WHERE sokarNr = @isokarNr

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000