Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 9th, 2003, 07:52 PM
kathy7012 kathy7012 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 1 kathy7012 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Problem with if() statement, comparing primary keys with trigger

Hi there,
I am relatively new to sql and I am not quite sure how to write this out, I hope you don't mind me asking. I am comparing emails in my database in an email table that has these fields. lngEmailPK, lngStudentFK, strAddress, and lngEmailValue. lngEmailValue is the value of their primary key, 1 if primary and 0 if not primary. I have the right idea I think, but maybe I am not implementing it correctly.
I want to do the following:

/*If they have multiple emails and more than one is primary - remove all primaries. Insert a non primary - make it a primary.
Insert a primary and they already have a primary - strip out and allow them to enter this one as the primary.*/

if(@lngEmailValue %2 = 1 and @lngEmailValue = +2)
delete from tblEmail
where lngEmailValue = 1 and @lngEmailValue = +2
select @@identity
set @lngEmailValue = -1

if(@lngEmailValue %2 = 0)
update tblEmail
set @lngEmailValue = @lngEmailValue + 1
where lngStudentFK = @lngStudentFK AND lngEmailValue %2 = 1

if(@lngEmailValue %2 = 1)
update tblEmail
set @lngEmailValue = lngEmailValue -1
where lngStudentFK = @lngStudentFK AND lngEmailValue %2 = 1 AND lngEmailPK = @lngEmailPK
select @@identity
set @lngEmailValue = 1

If you need my tables to reference, I will be more than happy to send them. Just let me know if you do. Thank you very much.

Reply With Quote
  #2  
Old June 12th, 2003, 10:14 AM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 52 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
I'm not entirely understanding what you're needing/wanting to do.. FYI, the Primary key is:
Quote:
primary key: A primary key uniquely identifies a row of data found within a table. Referring to the school system, the student identification number would be the primary key for the student table since an ID would uniquely identify each student.
Note that a primary key might not necessarily correspond to one specific attribute. In fact, it could be the result of a combination of several components of the entity. For example, while a location could not be a primary key for a class, since there might be several classes held there throughout the day, the combined time and location would make a satisfactory primary key, since no two classes could be held at the same time in the same location. When multiple attributes are used to derive a primary key, this key is known as a concatenated primary key.


Quote:
/*If they have multiple emails and more than one is primary - remove all primaries. Insert a non primary - make it a primary.
Insert a primary and they already have a primary - strip out and allow them to enter this one as the primary.*/


As for email management, this part right here is confusing me terribly.. are you wanting to do this so that they can mark the messages read/unread? or deleted/not deleted? What are you needing to do? why are you comparing the emails to the database? to confirm if they have been picked up yet?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Problem with if() statement, comparing primary keys with trigger


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT