Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

Sql

I have a table which has three columns as shown below.


USER        USERROLE             GROUP
-------       -------------            ---------

Tom          Tom                     READ
Tim           TimRW                 RW

I need sql that will check the values in USER column and compares it with the value in USERROLE column and if they both are equal/identical then it should insert a value READ in the GROUP column corrsponding to him , And when they are not eqaul it should insert RW.

many thanks.
0
crishna1
Asked:
crishna1
3 Solutions
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
UPDATE MyTable SET GROUP = 'READ' WHERE USER = USERROLE
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
UPDATE MyTable SET GROUP = 'RW' WHERE USER <> USERROLE
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
Two SQL statements will do the job.  This can probably also be done with an IF statement, but I'm not confident in my SQL Logic/Syntax to provide assistance on that.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
crishna1Author Commented:
There are instances where GROPID coumn has no value for certaing conrresponding USER records in that case i need the sql to insert based on teh above clause.

Also i guess checking all the above in one sql statment is a better idea.
0
 
rensmanCommented:
UPDATE MyTable SET GROUP =
CASE
  WHEN USER=USERROLE THEN 'READ'
  WHEN USER<> USERROLE THEN 'RW'
END
0
 
suprapto45Commented:
Hi,

I think that rensman has covered it. Well, another way to achieve it is to use Trigger but assuming that you use Oracle database. Please let me know if you want the sample of trigger or PL/SQL.

Best Regards
Dave
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now