Strange Insert scenario

  • All,

    I have faced two types of insert problem today.

    1) User will pass 5 input arguments, one argument will come up with comma seperated string.

    Say for example,

    1000,32,Getdate(),'01,02,03,04',userid()

    I have to split it into 4 parts and then need to insert into a table.

    Tally table comes to mind Immediately, so i splitted it by the following query.

    assume @str is declared as a input parament.

    set @str = ','+@str+','

    select @EmpId,@Age,getdate(),Substring(@Str,N+1,charindex(',',@Str,N+1)-N-1),userid()

    from Tally

    where N < Len(@Str)

    and substring(@Str,N,1) =','

    It works perfectly.

    But the second is looking very strange.

    Say for example,

    UI has 12 checkboxes , user may tick any of it,we don't know how many check boxes they have

    ticked.

    Now i want to insert the rows where the number of check boxes they have ticked. if it is 8 then 8 rows has to be inserted into the table. if it is 1 then a single row will be inserted into the table.

    Again ,shall i ask front end developers to pass it as a comma seperated string ? any suggestions ?

    Inputs are welcome !

    karthik

  • Some people have use XML to pass the data into the application. Or you can have the front end send multiple inserts.

  • I'd ask for a delimited string create a udf to handle delimited strings.

  • whether it is better to handle via DB side or from Front End side.

    karthik

  • It depends. If you do it from the UI, then you have n calls to the DB, each within it's own transaction or the UI developer has to manually start and commit a transaction. If you do it in the db it is one call and one transaction handled within the database. If all 12 boxes are checked does it need to be an all 12 succeed or all 12 fail? I'd lean toward doing it in the DB with the limited number of items in the list.

  • So i have to use loop to insert those records.

    karthik

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply