SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Update salary details without cursors


Update salary details without cursors

Author
Message
malleswarareddy_m
malleswarareddy_m
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2709 Visits: 1189
This is my sample data.

Empid Deptid Salary
1 2 3000
2 2 3500
4 4 5000
3 5 6000
6 6 7000
8 3 4000
9 2 6000
10 6 8000

Malleswarareddy
I.T.Analyst
MCITP(70-451)
ColdCoffee
ColdCoffee
SSCrazy Eights
SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)

Group: General Forum Members
Points: 8477 Visits: 5555
Mate, if u update the salary > 5000, it will constantly update everywhere. I dont think u need to search for values > 5000 in every department and update.. just update salary > 5000 to your value...

And , your post is seriously bad.. there was no explanantion on what to do except from the "Description" u had given in the thread.. please post a proper question , the DDLs , desired result... Sorry mate, a poster who has 794 posts should not be asking such a shabby question mate Sad


For those who are attempting to create a query for the poster, here are the DDLs..


IF OBJECT_ID('TEMPDB..#SALARY_DETAILS') IS NOT NULL
DROP TABLE #SALARY_DETAILS

CREATE TABLE #SALARY_DETAILS
(
EMP_ID INT,
DEP_ID INT,
SALARY INT
)

INSERT INTO #SALARY_DETAILS
SELECT 1,1, 6000
UNION ALL
SELECT 2,2, 2999
UNION ALL
SELECT 3,2, 6000
UNION ALL
SELECT 4,2, 5001
UNION ALL
SELECT 5,3, 3500
UNION ALL
SELECT 6,3, 5002

SELECT
EMP_ID,
DEP_ID,
SALARY
FROM
#SALARY_DETAILS



Cheers..
malleswarareddy_m
malleswarareddy_m
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2709 Visits: 1189
ok,

I want Particular departmant only.Just i copy and pasted this.next time i will post the sample data with proper format.not just for single update statement.It need to verify if that employee belongs to particular department and then update salary when his salary less than thousand else put same.

Malleswarareddy
I.T.Analyst
MCITP(70-451)
ColdCoffee
ColdCoffee
SSCrazy Eights
SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)

Group: General Forum Members
Points: 8477 Visits: 5555
Still very very unclear buddy.. can u post some sample query or visual samples of your requirement in accordance with the sample data i posted??
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)

Group: General Forum Members
Points: 91730 Visits: 38953
Basiclly, something like this:


update dbo.Employee set
Salary = Salary * 1.2 -- Increase Salary by 20%
where
DeptID = 3
and Salary < 1000.00



Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
ColdCoffee
ColdCoffee
SSCrazy Eights
SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)

Group: General Forum Members
Points: 8477 Visits: 5555
Lynn Pettis (4/12/2010)
Basiclly


:-D, Lynnn, thats very basic , isnt it.. :-P ... wonder how the OP missed filtering the rows directly by WHERE clause..
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)

Group: General Forum Members
Points: 91730 Visits: 38953
COldCoffee (4/12/2010)
Lynn Pettis (4/12/2010)
Basiclly


:-D, Lynnn, thats very basic , isnt it.. :-P ... wonder how the OP missed filtering the rows directly by WHERE clause..



Thinking procedurely instead of in a set-based manner. Asking what I need to do to a row instead of a column.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
ColdCoffee
ColdCoffee
SSCrazy Eights
SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)

Group: General Forum Members
Points: 8477 Visits: 5555
Oh yes.. :-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search