Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 rowcount(max)

Author  Topic 

Arun.G
Yak Posting Veteran

81 Posts

Posted - 2010-06-10 : 03:46:09
i got results from stroed prcedure like below:

slno effectivefrom status months
1 2009-10-05 trainee 7
2 2010-05-05 confirmed -

in front end the latest record(slno 2) only can be editable
the above one should be static

how to achieve this thrugh stored procedure in sqlserver 2008

using rowcount(max) or anytother methods?

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-06-10 : 04:00:32
Sorry but you are not clear.
What do you want the stored procedure to do or what is your problem?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Arun.G
Yak Posting Veteran

81 Posts

Posted - 2010-06-10 : 04:08:51
I have these columns from one table(EmpInfo):

effectivefrom statusid
2009-05-05 1

effectivefrom is nothing but the joiningdate of the employee and the statusid is coming from Master Table:Status
which has

statusid status
1 trainee
2 probation
3 confirmation

like that


i have another table Statuschange which has:

status_id empid effectivefrom statuschageid months remarks
1 1 2009-10-05 2 5 ok
2 1 2010-05-05 3 7 gud


like that,

here the Months colum should be updated automatically by finidnthe difference between latest statuschange to present change
i.e


in the status_id =1 row, the months 5 is the difference between the effectivefrom (empinfo table) and effectivefrom (statuschage table)
and status_id=2 months 7 is the difference from status_id=1 record's effectivefrom ann status_id=2 record's effectivefrom columns


Now i wnat the result like below:

slno effectivefrom statuschange months remarks action
1 2009-05-05 trainee 5 view
2 2009-10-05 probation 7 view
3 2010-05-05 confirmed - edit view

the first 2 records are only viewable, and the latest record(3) should only editable and viewable
how i can write the stored procedure for the above situtaion in sqlserver 2008?

pls help
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-06-10 : 05:19:51
You can use a trigger to do this.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -