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 ««123»»

Performance ISSUE by USING CURSOR HELP !!!! Expand / Collapse
Author
Message
Posted Monday, March 25, 2013 9:38 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, July 3, 2014 5:47 AM
Points: 68, Visits: 334
Hello,

OUTPUT INSERTED.YourIdentityColumn, INSERTED.easilyPatId

My identy colunm is tel_id but for the second output is INSERTED.@easilyPadId (value get from cursor). Is it correct ?

Thanks

Eric
Post #1434986
Posted Monday, March 25, 2013 9:46 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:19 AM
Points: 13,064, Visits: 11,897
ERIC CRUDELI (3/25/2013)
Hello,

OUTPUT INSERTED.YourIdentityColumn, INSERTED.easilyPatId

My identy colunm is tel_id but for the second output is INSERTED.@easilyPadId (value get from cursor). Is it correct ?

Thanks

Eric


I think you missed the point. You don't need those variables at all. What I posted would be the replacement for the ENTIRE cursor section. No variables, no cursors, no repetition.



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1434989
Posted Monday, March 25, 2013 9:55 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, July 3, 2014 5:47 AM
Points: 68, Visits: 334
I'm lost

The Data source I have to use for Insert is in Temporary table #temp2

Where is the link ?
Post #1434995
Posted Monday, March 25, 2013 10:00 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:19 AM
Points: 13,064, Visits: 11,897
ERIC CRUDELI (3/25/2013)
I'm lost

The Data source I have to use for Insert is in Temporary table #temp2

Where is the link ?


I'm sorry the code I posted wasn't very clear. Of course what I posted it 100% untested because we don't have ddl to work with.

See if this helps.

INSERT INTO [DI628SW].[NOYAU_PATIENT].[noyau].[TELEPHONE] (
tel_categorie
,tel_numero
,tel_envoi_sms
,tel_principal
,tel_commentaire
,tel_administratif
,tel_actif
)
OUTPUT INSERTED.YourIdentityColumn, INSERTED.easilyPatId
into [DI628SW].[NOYAU_PATIENT].[noyau].[TELEPHONE_PATIENT] (tel_id, pat_id)
SELECT etPatId,cnetNumTel,easilyTypeNumTelId,cnetnumeroPrincipal,cnetSMS,cnetCommentaire,easilyPatId, 0, 1
FROM #temp2



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1434997
Posted Monday, March 25, 2013 10:55 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, July 3, 2014 5:47 AM
Points: 68, Visits: 334
I got some errors.

1 - easilyPatId unknow (easilyPadId come from #temp2)
2 -target table ' DI628SW.NOYAU_PATIENT.noyau. TELEPHONE_PATIENT ' of the clause OUTPUT INTO cannot be next to a relation (primary key, foreign key). Constraint of found reference: ' FK_TELEPHONE_PATIENT_PATIENT '. Note tel_id is primary key and Identity field from [TELEPHONE ]but also a primary key but not identity from [TELEPHONE_PATIENT]

I think there something wrong in Ouput but I don't know where ?

INSERT INTO [DI628SW].[NOYAU_PATIENT].[noyau].[TELEPHONE] (
tel_categorie
,tel_numero
,tel_envoi_sms
,tel_principal
,tel_commentaire
,tel_administratif
,tel_actif
)
OUTPUT INSERTED.tel_id, INSERTED.easilyPatId
into [DI628SW].[NOYAU_PATIENT].[noyau].[TELEPHONE_PATIENT] (tel_id, pat_id)
SELECT
easilyTypeNumTelId,
cnetNumTel,
cnetSMS,
cnetnumeroPrincipal,
cnetCommentaire,
0,
1
FROM #temp2
Post #1435049
Posted Monday, March 25, 2013 12:12 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:19 AM
Points: 13,064, Visits: 11,897
Syntactically it appears to be just fine. If there are logic issues I can't do much to help because there is no ddl to work with. Please take a few minutes and read the first in my signature for best practices when posting questions.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1435083
Posted Thursday, March 28, 2013 2:05 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:57 AM
Points: 7,115, Visits: 13,476
ERIC CRUDELI (3/25/2013)
I got some errors.

1 - easilyPatId unknow (easilyPadId come from #temp2)
2 -target table ' DI628SW.NOYAU_PATIENT.noyau. TELEPHONE_PATIENT ' of the clause OUTPUT INTO cannot be next to a relation (primary key, foreign key). Constraint of found reference: ' FK_TELEPHONE_PATIENT_PATIENT '. Note tel_id is primary key and Identity field from [TELEPHONE ]but also a primary key but not identity from [TELEPHONE_PATIENT]

I think there something wrong in Ouput but I don't know where ?

INSERT INTO [DI628SW].[NOYAU_PATIENT].[noyau].[TELEPHONE] (
tel_categorie
,tel_numero
,tel_envoi_sms
,tel_principal
,tel_commentaire
,tel_administratif
,tel_actif
)
OUTPUT INSERTED.tel_id, INSERTED.easilyPatId
into [DI628SW].[NOYAU_PATIENT].[noyau].[TELEPHONE_PATIENT] (tel_id, pat_id)
SELECT
easilyTypeNumTelId,
cnetNumTel,
cnetSMS,
cnetnumeroPrincipal,
cnetCommentaire,
0,
1
FROM #temp2


Hi Eric

You are using four-part naming for your tables and referring to two different servers, DI81SW & DI628SW. Are both of these linked servers? Can you identify which server you are connected to when you are running this code?
Cheers


“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Post #1436299
Posted Thursday, March 28, 2013 2:14 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, July 3, 2014 5:47 AM
Points: 68, Visits: 334
I ran the script on DI628SW
Post #1436302
Posted Thursday, March 28, 2013 2:19 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:57 AM
Points: 7,115, Visits: 13,476
ERIC CRUDELI (3/28/2013)
I ran the script on DI628SW


This is where it will be run from always?
The other server - DI81SW - this is a linked server?


“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Post #1436304
Posted Thursday, March 28, 2013 2:26 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, July 3, 2014 5:47 AM
Points: 68, Visits: 334
Yes all the time on DI628SW. DI81SW server linked
Post #1436307
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse