insert into po_detail (item_code,qty,item_rate,item_tax) select a.item_code,qty,item_rate,item_tax from mr_detail a,mr_head b where a.mr_no = " & combo_mr_no.Text & " and a.mr_no=b.mr_no""

what's the error in the above code ?

Recommended Answers

All 3 Replies

If item_code, qty, item_rate and item_tax are unique then they don't have to be qualified (as in with a. or b. but it is good practice to qualify them anyway for clarity.

You didn't give the entire line of code. You are building a string query but I can't see the assignment or even the opening quotes so I can't speak as to syntax. You also need to surround text values in single quotes. I find it helps to format query strings so each portion of a clause is on its own line. It makes it easier to read and spot syntax errors. Replace the ?. in the following with the appropriate qualifiers (a., b.) and try

query = "insert into po_detail (item_code,qty,item_rate,item_tax)" _
      & "  select  a.item_code, ?.qty, ?.item_rate, ?.item_tax" _
      & "    from  mr_detail a, mr_head b" _
      & "    where a.mr_no = b.mr_no" _
      & "      and a.mr_no = '" & combo_mr_no.Text & "'"

I think you miss the "Values()" part.

Insert Into Table1(Field1,Field2,.....) Values(Val1,Val2,.....)

This is the correct form of SQL Insert...

You don't use the Values keyword if the values come from a subordinate select clause.

commented: Thanks for this tips... +5
commented: True +9
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.