Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
USE command in SP
Message
 
 
To
10/10/2005 00:25:49
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01057586
Message ID:
01057625
Views:
30
>So, it mean that I can't apply the db change to my SP alone.

Yes.

>BTW, any good way to avoid using cursor in SP ?
>It really slowing my performance.


You'll get the best performance usually with set oriented processing (queries) because SQL Server is optimized for it. So your first step would be to see if you can do the processing with a query. If you still have to do processing record by record, you can replace SQL cursor with a TABLE variable or temp table as shown below. I'm not sure how faster it will be but I like it better because it's more flexible.
-- TABLE variable
-- pubs DB
DECLARE @PkList TABLE ( seq int IDENTITY, au_id varchar(11))
DECLARE @RecCount int, @i int
INSERT INTO @PkList (au_id) 
		SELECT au_id from authors ORDER BY state, city

SET @RecCount = @@ROWCOUNT

DECLARE @au_fname varchar(20), @au_lname varchar(40)
SET @i = 1
WHILE @i <= @RecCount BEGIN
	SELECT @au_fname = au.au_fname, @au_lname = au.au_lname
		FROM @PkList pk
			JOIN authors au on au.au_id = pk.au_id
				AND pk.seq = @i
		PRINT RTRIM(@au_fname) + SPACE(1) + RTRIM(@au_lname)		
	SET @i = @i + 1
END	

RETURN
--------------------------------------------------------------------
-- Temp Table
-- pubs DB
DECLARE @RecCount int, @i int
SELECT IDENTITY(int) AS seq, au_id
	INTO #PkList 
	FROM authors ORDER BY state, city

SET @RecCount = @@ROWCOUNT

DECLARE @au_fname varchar(20), @au_lname varchar(40)
SET @i = 1
WHILE @i <= @RecCount BEGIN
	SELECT @au_fname = au.au_fname, @au_lname = au.au_lname
		FROM #PkList pk
			JOIN authors au on au.au_id = pk.au_id
				AND pk.seq = @i
		PRINT RTRIM(@au_fname) + SPACE(1) + RTRIM(@au_lname)		
	SET @i = @i + 1
END	

DROP TABLE #PkList
RETURN
>In addition, why is it that when I am using
>dynamic SQL, some of the string will be truncated
>
> DECLARE @execstr varchar(4000)
>
> SET @execstr = 'DECLARE ....'+
> '....'+
> '.....'
>
> SELECT @execstr
>
>
> Some of the string will be display. Please advise and comment,


I'm not sure what you mean. Where're they truncated?
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform