Connecting Tech Pros Worldwide Forums | Help | Site Map

Split value and insert into query

Member
 
Join Date: Apr 2008
Posts: 66
#1: Sep 5 '08
Hi all.

I have problem with this asp code:

Expand|Select|Wrap|Line Numbers
  1. strSplitDati = Split(request.Form("dati"), ",")
  2.  
  3.         for i = LBound(strSplitDati) to (INT(UBound(strSplitDati)/4)-1)*4 step 4
  4.  
  5.  
  6. strSql = " INSERT INTO "
  7. strSql = strSql & " tbl "
  8. strSql = strSql & " ( "
  9. strSql = strSql & " ID_UEV, "
  10. strSql = strSql & " UEV, "
  11. strSql = strSql & " testo_A, "
  12. strSql = strSql & " testo_B, "
  13. strSql = strSql & " numero_A, "
  14. strSql = strSql & " numero_B "
  15. strSql = strSql & " ) "
  16. strSql = strSql & "   VALUES "
  17. strSql = strSql & " ( "
  18. strSql = strSql & "   " & replace(strUEV(0), "'", "''") & ", "
  19. strSql = strSql & "  '" & replace(strUEV(1), "'", "''") & "', "
  20.  
  21.  
  22. if Trim(strSplitDati(i) & "[]") <> "[]" AND Trim(strSplitDati(i+1) & "[]") <> "[]" AND _
  23.    Trim(strSplitDati(i+2) & "[]") <> "[]" AND Trim(strSplitDati(i+3) & "[]") <> "[]" _
  24. then
  25.    strSql = strSql & ",'" & strSplitDati(i) & "' "
  26.    strSql = strSql & ",'" & strSplitDati(i+1) & "' "
  27.    strSql = strSql & "," & strSplitDati(i+2) & " "
  28.    strSql = strSql & "," & strSplitDati(i+3) & " "
  29.  
  30. else
  31.  
  32.    strSql = strSql & ", '-' "
  33.    strSql = strSql & ", '-' "
  34.    strSql = strSql & ", -1 "
  35.    strSql = strSql & ", -1 "  
  36.  
  37. end if
  38.  
  39. strSql = strSql & " ) "
  40. cn.execute strSql
  41.  
  42. response.write strSQL & "<br /><br />"
  43.  
  44. next
this code write this :

Quote:
INSERT INTO tbl ( ID_UEV, UEV, testo_A, testo_B, numero_A, numero_B ) VALUES ( 1, 'TRLM', '-' , '-' , -1 , -1 )

INSERT INTO tbl ( ID_UEV, UEV, testo_A, testo_B, numero_A, numero_B ) VALUES ( 1, 'TRLM', '-' , '-' , -1 , -1 )

INSERT INTO tbl ( ID_UEV, UEV, testo_A, testo_B, numero_A, numero_B ) VALUES ( 1, 'TRLM', '-' , '-' , -1 , -1 )

INSERT INTO tbl ( ID_UEV, UEV, testo_A, testo_B, numero_A, numero_B ) VALUES ( 1, 'TRLM', '-' , '-' , -1 , -1 )

INSERT INTO tbl ( ID_UEV, UEV, testo_A, testo_B, numero_A, numero_B ) VALUES ( 1, 'TRLM', '-' , '-' , -1 , -1 )

INSERT INTO tbl ( ID_UEV, UEV, testo_A, testo_B, numero_A, numero_B ) VALUES ( 1, 'TRLM', 'CS7' ,'Ins' ,1 ,2 )

INSERT INTO tbl ( ID_UEV, UEV, testo_A, testo_B, numero_A, numero_B ) VALUES ( 1, 'TRLM', 'CS8' ,'Suf' ,3 ,4 )
and not this: why ????

Quote:
INSERT INTO tbly ( ID_UEV, UEV, testo_A, testo_B, numero_A, numero_B ) VALUES ( 1, 'TRLM', '-' , '-' , -1 , -1 )

INSERT INTO tbly ( ID_UEV, UEV, testo_A, testo_B, numero_A, numero_B ) VALUES ( 1, 'TRLM', 'CS7' ,'Ins' ,1 ,2 )

INSERT INTO tbly ( ID_UEV, UEV, testo_A, testo_B, numero_A, numero_B ) VALUES ( 1, 'TRLM', 'CS8' ,'Suf' ,3 ,4 )

jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#2: Sep 7 '08

re: Split value and insert into query


print out the request.form("dati"). What does it say?

My first impression is that your "for" statement is too complicated. It might be easier to say
Expand|Select|Wrap|Line Numbers
  1. for each i in strsplitdati
(i think that's what you are trying to do, but your statement is so complicated, I'm not sure I follow it.)

Jared
Reply