May 12, 2008 at 8:48 am
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
May 12, 2008 at 9:00 am
Some people have use XML to pass the data into the application. Or you can have the front end send multiple inserts.
May 12, 2008 at 9:07 am
I'd ask for a delimited string create a udf to handle delimited strings.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
May 12, 2008 at 9:13 am
whether it is better to handle via DB side or from Front End side.
karthik
May 12, 2008 at 10:03 am
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.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
May 14, 2008 at 3:40 am
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