Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Performance ISSUE by USING CURSOR HELP !!!!


Performance ISSUE by USING CURSOR HELP !!!!

Author
Message
ERIC CRUDELI
ERIC CRUDELI
SSC Journeyman
SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)

Group: General Forum Members
Points: 80 Visits: 503
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
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16515 Visits: 16989
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)
ERIC CRUDELI
ERIC CRUDELI
SSC Journeyman
SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)

Group: General Forum Members
Points: 80 Visits: 503
I'm lost Doze

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

Where is the link ?
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16515 Visits: 16989
ERIC CRUDELI (3/25/2013)
I'm lost Doze

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
      Wink
      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)
ERIC CRUDELI
ERIC CRUDELI
SSC Journeyman
SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)

Group: General Forum Members
Points: 80 Visits: 503
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
      Wink
      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
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16515 Visits: 16989
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)
ChrisM@Work
ChrisM@Work
SSCrazy Eights
SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)

Group: General Forum Members
Points: 8923 Visits: 19005
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
      Wink
      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
ERIC CRUDELI
ERIC CRUDELI
SSC Journeyman
SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)

Group: General Forum Members
Points: 80 Visits: 503
I ran the script on DI628SW
ChrisM@Work
ChrisM@Work
SSCrazy Eights
SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)

Group: General Forum Members
Points: 8923 Visits: 19005
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
ERIC CRUDELI
ERIC CRUDELI
SSC Journeyman
SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)

Group: General Forum Members
Points: 80 Visits: 503
Yes all the time on DI628SW. DI81SW server linked
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search