简体   繁体   English

使用Select语句和from函数插入表中

[英]insert into a table using the Select statement and from function

I am trying to insert into a table using the Select statement and get values from function. 我试图使用Select语句插入表中并从函数中获取值。

INSERT INTO  TABLE1 
          ([Col1]
           , [Col2]
           ,[Col3]
           ,[Col4]
           ,[Col5]
           ,[CreationDate]
           ,[CreatedBy]                  
           )  
           VALUES         
 ((Select [Col1],[Col2],[Col3],[Col4
  FROM TABLE2)dbo.FUNTION(paramiter) ,SYSDATETIME(), UPPER('USERNAME'))

NOTE: im usring SQL SERVER 2008R2. 注意:正在使用SQL SERVER 2008R2。 please let me know how to do this? 请让我知道该怎么做?

Thanks guys cheers 谢谢大家的欢呼

您需要使用以下语法:

INSERT INTO table(columns) SELECT ...

Make your select statement work first, and then INSERT INTO TABLE1 ([col1], [col2]...) SELECT... 首先使您的select语句起作用,然后将INSERT INTO TABLE1([col1],[col2] ...)SELECT ...

Since your Select statement is broken right now, the insert is also broken. 由于您的Select语句现在已损坏,因此插入操作也已损坏。 Fix your select to something like 将您的选择固定为类似

Select [Col1],[Col2],[Col3],[Col4],dbo.FUNCTION(parameter), SYSDATETIME(), UPPER('USERNAME')
  FROM TABLE2 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM