Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Update salary details without cursors Expand / Collapse
Author
Message
Posted Monday, April 12, 2010 10:24 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, July 21, 2014 3:43 AM
Points: 1,939, Visits: 1,162
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)
Post #902120
Posted Monday, April 12, 2010 10:58 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, September 12, 2014 5:21 PM
Points: 2,262, Visits: 5,406
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


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..
Post #902126
Posted Monday, April 12, 2010 11:08 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, July 21, 2014 3:43 AM
Points: 1,939, Visits: 1,162
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)
Post #902129
Posted Monday, April 12, 2010 11:29 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, September 12, 2014 5:21 PM
Points: 2,262, Visits: 5,406
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??
Post #902135
Posted Monday, April 12, 2010 11:47 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 10:34 AM
Points: 20,682, Visits: 32,282
Basiclly, something like this:

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




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)
Post #902138
Posted Monday, April 12, 2010 11:53 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, September 12, 2014 5:21 PM
Points: 2,262, Visits: 5,406
Lynn Pettis (4/12/2010)
Basiclly


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

Post #902140
Posted Monday, April 12, 2010 11:59 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 10:34 AM
Points: 20,682, Visits: 32,282
COldCoffee (4/12/2010)
Lynn Pettis (4/12/2010)
Basiclly


, Lynnn, thats very basic , isnt it.. ... 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.



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)
Post #902142
Posted Tuesday, April 13, 2010 12:39 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, September 12, 2014 5:21 PM
Points: 2,262, Visits: 5,406
Oh yes..
Post #902150
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse