|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
||||
|
||||
|
I'm not entirely understanding what you're needing/wanting to do.. FYI, the Primary key is:
Quote:
Quote:
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? |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft SQL Server > Problem with if() statement, comparing primary keys with trigger |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|