Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update column based on constraints

Status
Not open for further replies.

Ken

IS-IT--Management
Jul 13, 2005
68
CA
Hi All,

[highlight #204A87]Want to update a column based on 2 columns at Table level and would like some help.[/highlight]

Code:
Current Table structure: tblCheckId
    RightId text(25), WrongId text(25), RightId_chk text(1)

Indexes in TblCheckId:
Indx1  is RightId+RightId_Chk  in this combination Unique as Yes
Indx2  is WrongId              Unique as Yes

Value in table: tblCheckId 
    RightId	  WrongId       RightId_Chk
    Material1		        Y
    Material1     mtrl1
    Material1     Mtrial1

[b]Gives error in below sql:[/b]
ALTER table tblCheckId
ADD constraint (RightId is not null AND 
                WrongId is null references tblcheckid 
                on UPDATE SET RightId_chk ="Y")

Error: constraint clause


How to UPDATE columnn RightId_Chk to value 'Y' only when
RightId is Not Null and WrongId is null

or is there another way to achieve this condition.


Thanks,

IT-Tech
 
SQL:
UPDATE tblCheckId SET RightId_chk ='Y' WHERE RightId IS NOT NULL AND WrongId IS NULL

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
[tt]UPDATE tblCheckId
SET RightId_Chk = 'Y'
WHERE RightId IS NOT NULL
AND WrongId IS NULL[/tt]

Have fun.

---- Andy
 
Hi All,

Can we store UPDATE command with the table itself ?
That is when a user enters material in column RightId and WrongId is left blank, RightId_Chk is updated to Y.

The UPDATE command should run by itself like a trigger in access 2010.

IT-Tech
 
Hi All,

Thanks, it is working.

In Access 2010 you go to design mode, In design mode select the field getting updated e.g. rightid, than click icon Create Data Macro, select Before change and use the condition.

Thanks for all you help.

IT-Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top