如何使用带有变量而不是值的SQL插入 [英] How to use SQL Insert with variable instead of value

查看:135
本文介绍了如何使用带有变量而不是值的SQL插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我将记录从1个表复制到另一个表时,我使用Rnd创建了一个唯一编号,因此该值也应该复制到名为UniqNumber的第二个表列中。


如何我可以通过将UniqNumber存储到table-2列中来实现吗?


任何专家可以帮助我吗?



下面的语句将创建一个错误 -

展开 | 选择 | Wrap | 行号

解决方案

这不是看起来像一个唯一的数字:(。



对不起,这只是我的输入错误,但是有更好的方法来创建一个唯一的数字,我如何在下面的语句中使用sql插入


dim POID long


POID =使用某种方法来创建唯一的nos并存储到此变量中


Dim strstmt As String


strstmt =" insert into tblinvoicelines(custID,customer,ProductID ,POID)选择来自tblorderlines的custID,customer,ProductID,POID,其中po =" &安培; lstSearch.Column(0) '' FrmOrderSubform.Form!PO


DoCmd.RunSQL strstmt


我的问题是我不能使用POID,因为它sql语句中的变量对吗?


Everytime I copy records from 1 table to another table, I created a Unique number using Rnd, so this value should also be copied into the 2nd table column called UniqNumber.

How can I achieve by storing the UniqNumber into the table-2 column ?

Any Expert out there could help me ?


Here below statement will created an error -

Expand|Select|Wrap|Line Numbers

解决方案

That doesn''t look like a unique number :(.


Also your DoCmd.RunSQL refers to strstmt but the string you set up with the SQL is called sqt.


Sorry, it just my typing error, but is there a better way to create a unique number and how do I use sql to insert in the below statement

dim POID long

POID = "using some method to create unique nos and store into this variable"

Dim strstmt As String

strstmt = "insert into tblinvoicelines(custID, customer, ProductID, POID) select custID, customer, ProductID,POID from tblorderlines where po = " & lstSearch.Column(0) '' FrmOrderSubform.Form!PO

DoCmd.RunSQL strstmt

My question is I cannot use POID as it a variable inside the sql statement right ?


这篇关于如何使用带有变量而不是值的SQL插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆