Click here to Skip to main content
15,920,383 members
Home / Discussions / Database
   

Database

 
GeneralRe: Inserting special characters in SQL 2000 Pin
Anonymous19-May-04 1:29
Anonymous19-May-04 1:29 
GeneralRe: Inserting special characters in SQL 2000 Pin
Rob Graham15-May-04 2:54
Rob Graham15-May-04 2:54 
GeneralEmbarcadero Rapid SQL Pin
Nino_113-May-04 15:57
Nino_113-May-04 15:57 
GeneralRe: Embarcadero Rapid SQL Pin
mtone18-May-04 7:26
mtone18-May-04 7:26 
GeneralRow Concatenation Pin
Ruchi Gupta13-May-04 13:08
Ruchi Gupta13-May-04 13:08 
GeneralRe: Row Concatenation Pin
Bill Dean18-May-04 5:20
Bill Dean18-May-04 5:20 
GeneralRe: Row Concatenation Pin
Ruchi Gupta18-May-04 5:40
Ruchi Gupta18-May-04 5:40 
GeneralRe: Row Concatenation Pin
Bill Dean18-May-04 6:10
Bill Dean18-May-04 6:10 
Ruchi Gupta wrote:
But it is kind of expensive operation, when temp table is huge

Agreed. Which is why I was trying to be clever...the update...from is often handy for complex updates, but I can't come up with a single query that will generate your desired result strings ('100,200,300','400', etc). Besides, that approach required that you know the max number of strings (in your example, 3) before hand.

You mention passing parameters for the first time above. Are you updating only a few records in TB1? That might make this easier. I was assuming you were updating the whole table.

Anyway in ADO, the idea is to get your data from TB2 in order, loop through the results building the new IDs string for each entry in TB1 and then do the update. C# doesn't suffer from the horrible performance penalties of SQL for looping.

Something like:

-Load TB1 into a DataTable using a dataadapter (if you set the PK, you can use a SqlCommandBuilder to automatically generate your update command)
-Load TB2, sorted by DT,Desk into a second datatable
-create a string variable to accumulate the id string;
-Cycle through every row of this second table.
-if the current row has the same DT and Desk as the previous row, just add the ID to the id string with the comma
-other wise, set the IDs column of the Row in the first DataTable with the matching DT and Desk to the accumulated ID string. Use DataTable.Find() to find the row. Clear the ID string.

-At the end, use the original dataadapter to update the database.

This way, you can do all the itteration in C#, which does it well, rather than in SQL which is terrible at it.

Hope this helps
Bill
Generaldatabase location Pin
Anonymous13-May-04 11:44
Anonymous13-May-04 11:44 
GeneralRe: database location Pin
Jeff Varszegi13-May-04 12:01
professionalJeff Varszegi13-May-04 12:01 
GeneralRe: database location Pin
Anonymous13-May-04 12:26
Anonymous13-May-04 12:26 
GeneralRe: database location Pin
Jeff Varszegi13-May-04 13:19
professionalJeff Varszegi13-May-04 13:19 
GeneralRe: database location Pin
Anonymous13-May-04 14:04
Anonymous13-May-04 14:04 
GeneralRe: database location Pin
Jeff Varszegi13-May-04 14:54
professionalJeff Varszegi13-May-04 14:54 
GeneralRe: database location Pin
Anonymous13-May-04 15:41
Anonymous13-May-04 15:41 
GeneralRe: database location Pin
Jeff Varszegi15-May-04 2:43
professionalJeff Varszegi15-May-04 2:43 
GeneralRe: database location Pin
Anonymous15-May-04 4:17
Anonymous15-May-04 4:17 
QuestionImage problem??? Pin
Small Rat13-May-04 9:24
Small Rat13-May-04 9:24 
AnswerRe: Image problem??? Pin
Hesham Amin13-May-04 21:50
Hesham Amin13-May-04 21:50 
GeneralCross-tab query Pin
Ole12313-May-04 8:14
Ole12313-May-04 8:14 
GeneralRe: Cross-tab query Pin
-Dr_X-13-May-04 10:57
-Dr_X-13-May-04 10:57 
GeneralRe: Cross-tab query Pin
Ole12314-May-04 8:18
Ole12314-May-04 8:18 
GeneralUDF and Table Column Formula Pin
Wackatronic13-May-04 7:06
Wackatronic13-May-04 7:06 
GeneralRe: UDF and Table Column Formula Pin
Grimolfr19-May-04 8:51
Grimolfr19-May-04 8:51 
GeneralData access problem Pin
damoonlight12-May-04 16:27
damoonlight12-May-04 16:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.