Click here to Skip to main content
15,885,954 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have one table with column name account names.i have some predefined values for account like bankAC,loanAc,salesAc etc etc. i am updating my account table with account names. and this predefined accounts are not allowed to delete.only user created accounts are allowed to delete. and i have id with scope identity.


i want user created group name(Account group names)should be updated and predefined group names should not be updated.

What I have tried:

i have this update procedure

BEGIN

--SET NOCOUNT ON;
UPDATE tbl_AccountGroup SET Group_name = @Group_name, Comments = @Comments, chbox = @chbox, Under_Group= @Under_Group
WHERE Group_name = @Group_name;
END
Posted
Updated 16-Mar-16 4:15am
Comments
OriginalGriff 16-Mar-16 4:20am    
Why are you setting the Group_name to the value that you use for selecting the records for update?
Think about it: if it matches the WHERE clause, it already contains the value you are setting it to...

For the rest of your question I don't understand what problem you are having, or what help you need.
Perhaps an example of your data before and after the operation you want would help?
Use the "Improve question" widget to edit your question and provide better information.
CHill60 16-Mar-16 5:51am    
OP is trying to respond via a solution
"because i want to update group name also but with the same id. i have id as primary key with scope identity.but if i use id then it is not updating anything" (sic)
CHill60 16-Mar-16 5:54am    
Which code is it ... the sample you have here (which is silly - see OriginalGriff's comment) or the sample you gave on How to update all the columns in the table having scope identity id as primary key[^].
Delete one of your posts and make sure the other one has the correct code sample in it. Use the Improve question link to do this

The way you have described your update does not make any sense, but if you do not want to update certain records then you need to exclude them in a WHERE clause.

SQL
UPDATE table1 
SET field1 = @field1
WHERE group_name NOT IN('one', 'two', 'three')


I would also suggest adding a flag column to that table, a bit would work, and 1 means it is a system record and cannot be touched and 0 means it was created by user. It will make finding them much easier.
 
Share this answer
 
Comments
Member 12385326 17-Mar-16 2:29am    
UPDATE table1
SET field1 = @field1
WHERE group_name NOT IN('one', 'two', 'three') this query is updating all records which are not in where clause with same value.
ZurdoDev 17-Mar-16 7:04am    
Right, change it to what you need.
Member 12385326 17-Mar-16 7:24am    
but it is updating each record not specific record.enen if i changed where clause according to my need.
ZurdoDev 17-Mar-16 8:06am    
Can you clearly explain what you need to do?
Member 12385326 18-Mar-16 2:25am    
i want to update my user defined record only not system record. but if i use above query then it is updatating every record which are not in where condition.
I get the impression your update won't work because a constraint is blocking it, you could try the following (make a backup first):

SQL
ALTER TABLE tbl_AccountGroup NOCHECK CONSTRAINT ALL
-- Do your thing, e.g.
DROP TABLE tbl_AccountGroup
ALTER TABLE tbl_AccountGroup CHECK CONSTRAINT ALL
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900