June 26, 2009 at 1:06 am
I would say "none"...
I don't see anything that can't be done with a set-based solution, which performs much better. I suggest you to try to convert this into a set based update, maybe using some sort of temp table to store the data you are working with.
Regards
Gianluca
-- Gianluca Sartori
June 26, 2009 at 2:11 am
are both same.
can you give me some example.
Tanx 😀
June 26, 2009 at 2:23 am
Eswin (6/26/2009)
are both same.can you give me some example.
Maybe if you could explain what the innards of that cursor are supposed to do, someone can help. It's rather hard reverse-engineering a cursor.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 26, 2009 at 3:15 am
I want to fetch one row at a time and then satisfy the conditions following while @@row_count 0 and while @@fetch_status = 0 .
Will using SELECT statement that assigns values to a variables and then using "while @@row_count 0" allow me to fetch one row at a time and perform queries on it.
Tanx 😀
June 26, 2009 at 3:32 am
Eswin (6/26/2009)
Will using SELECT statement that assigns values to a variables and then using "while @@row_count 0" allow me to fetch one row at a time and perform queries on it.
Yes, but it's no better than a cursor. It's still row-by-row processing. I's still going to be slow. The best way to move on from here is to work out what needs doing to the resultset as a whole (not one row at a time) and convert this entire piece into set-based code.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 29, 2009 at 3:26 pm
If you are interested in a set-based solution you might try giving us DDL, sample data and expected output in addition explaining what you are actually trying to do.
I'm not sure if this'll help or not:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
June 29, 2009 at 4:21 pm
Hi Eswin,
just a few thoughts while you're working on providing the data:
- since you're using DATEPART(WEEKDAY ...) function you need to make sure that the setting for @@datefirst is a value you expect. I'd recommend to use SET DATEFIRST ... at the beginning of your proc.
- your "double-if"
If @day != 1
begin
If @day != 7
begin
can be replaced by IF @day >1 AND @day < 7 (in a set based solution this most probably would go the the WHERE clause)
- you should separate the insert and the update statement in two statements. The @count condition can be replaced by EXISTS rsp. NOT EXIST (to determine what rows need to be updated and what rows need to get inserted) EDIT: or by using inner rsp. left outer join.
July 4, 2009 at 12:53 pm
For your date range search, do not use all these filters
and ( ( ( leave.leave_start_dt between @start_date and @end_date)
and (leave.leave_end_dt between @start_date and @end_date) )
or leave.leave_start_dt >= @start_date and leave.leave_start_dt = @start_date and leave.leave_end_dt <= @end_date
or leave.leave_start_dt = @end_date)
Use this simple one instead
and leave.leave_start_dt = @start_date
N 56°04'39.16"
E 12°55'05.25"
July 4, 2009 at 6:21 pm
Eswin (6/26/2009)
I want to fetch one row at a time and then satisfy the conditions following while @@row_count 0 and while @@fetch_status = 0 .
That would be the problem... you have already resigned yourself to working whatever this problem is to one row at a time. Stop thinking about rows... start thinking about what you want to do to a column.
And I agree with the others. State what the problem actually is... not how you think it needs to be solved.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 9 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply