在 insert select 命令 sql c# 中从文本框中添加行
add rows from textbox in insert select command sql c#
我正在创建一个 Web 应用程序,我在其中使用插入 select 命令
为此我采用了如下所示的存储过程
alter PROCEDURE profinalinstexpensesonid
(
@from varchar(5000),
@to varchar(5000),
@trainer varchar(5000),
@sonvinid varchar(5000),
@button varchar(5000),
@bill_id varchar(5000)
)
AS
BEGIN
if(@button='allselect')
begin
insert into listinvoice(sonvinid,tid,date,brandname,zone,location,area,venuename,venue,instructore,amount)
select
instructoreexpense.sonvinid,
sonvininsert.trainer,
convert(varchar,sonvininsert.date,105) as date ,
sonvininsert.brandname,
substring(sonvininsert.zone,1,1)as zone,
sonvininsert.location,
sonvininsert.area,
companysonvinunitvenue.venuename,
sonvininsert.venue,
sonvininsert.instructore,
instructoreexpense.amount
from
instructoreexpense
left outer join sonvininsert on
sonvininsert.sonvinid=instructoreexpense.sonvinid and
sonvininsert.status='0'
left outer join finalinstructoreexpense on
finalinstructoreexpense.sonvinid=instructoreexpense.sonvinid
left outer join companysonvinunitvenue on
companysonvinunitvenue.id=sonvininsert.comsonvinid
where
sonvininsert.sonvinid not in(select sonvinid from listinvoice)
and
sonvininsert.date
between convert(datetime,@from,105) and
convert(datetime,@to,105) and
sonvininsert.trainer=(select empname from trainerdetails where trid=@trainer)
and instructoreexpense.sonvinid NOT IN (
SELECT CAST(Item AS INTEGER)
FROM SplitString(@sonvinid, ',')
)
order by instructoreexpense.sonvinid
end
end
现在一切正常,现在在这条线上
insert into listinvoice(sonvinid,tid,date,brandname,zone,location,area,venuename,venue,instructore,amount)
我想添加bill_id
我将从我程序中的文本框中获取我的bill_id
所以我想把这一行改成这样
insert into listinvoice(sonvinid,tid,date,brandname,zone,location,area,venuename,venue,instructore,amount,bill_id=@bill_id)
但我发现了
的错误
Msg 102, Level 15, State 1, Procedure profinalinstexpensesonid, Line
14 Incorrect syntax near '='.
我需要做什么,
我正在从我的文本框中获取 bill_id,
还有其他选择吗???
问题出在您的 INSERT
语句上:
insert into listinvoice(sonvinid,tid,date,brandname,zone,
location,area,venuename,venue,instructore,amount,bill_id=@bill_id)
您还没有完成声明。您通常会像这样格式化它:
INSERT INTO (Col1, Col2, Col3) VALUES (@Val1, @Val2, @Val3)
您将首先在第一组中列出要为其提供值的列,然后在关键字 VALUES
之后的第二组中列出值本身。
在您的列表中,您似乎列出了要插入的列,但最后一列除外,您还试图在其中以某种方式分配一个值。你需要这样的东西:
insert into listinvoice(sonvinid,tid,date,brandname,zone,
location,area,venuename,venue,instructore,amount,bill_id)
VALUES (@sonvinid, ..., @bill_id)
显然,您需要将省略号替换为您的实际参数。
你必须改变你的说法。您目前正在这样做:
insert into listinvoice(sonvinid,tid,date,brandname,zone,location,area,venuename,venue,instructore,amount,bill_id=@bill_id)
应该是这样的:
insert into listinvoice(sonvinid,tid,date,brandname,zone,location,area,venuename,venue,instructore,amount,bill_id)
select
instructoreexpense.sonvinid,
sonvininsert.trainer,
convert(varchar,sonvininsert.date,105) as date ,
sonvininsert.brandname,
substring(sonvininsert.zone,1,1)as zone,
sonvininsert.location,
sonvininsert.area,
companysonvinunitvenue.venuename,
sonvininsert.venue,
sonvininsert.instructore,
instructoreexpense.amount,
@bill_id
from
instructoreexpense
left outer join sonvininsert on
sonvininsert.sonvinid=instructoreexpense.sonvinid and
sonvininsert.status='0'
left outer join finalinstructoreexpense on
finalinstructoreexpense.sonvinid=instructoreexpense.sonvinid
left outer join companysonvinunitvenue on
companysonvinunitvenue.id=sonvininsert.comsonvinid
where
sonvininsert.sonvinid not in(select sonvinid from listinvoice)
and
sonvininsert.date
between convert(datetime,@from,105) and
convert(datetime,@to,105) and
sonvininsert.trainer=(select empname from trainerdetails where trid=@trainer)
and instructoreexpense.sonvinid NOT IN (
SELECT CAST(Item AS INTEGER)
FROM SplitString(@sonvinid, ',')
)
order by instructoreexpense.sonvinid
我正在创建一个 Web 应用程序,我在其中使用插入 select 命令
为此我采用了如下所示的存储过程
alter PROCEDURE profinalinstexpensesonid
(
@from varchar(5000),
@to varchar(5000),
@trainer varchar(5000),
@sonvinid varchar(5000),
@button varchar(5000),
@bill_id varchar(5000)
)
AS
BEGIN
if(@button='allselect')
begin
insert into listinvoice(sonvinid,tid,date,brandname,zone,location,area,venuename,venue,instructore,amount)
select
instructoreexpense.sonvinid,
sonvininsert.trainer,
convert(varchar,sonvininsert.date,105) as date ,
sonvininsert.brandname,
substring(sonvininsert.zone,1,1)as zone,
sonvininsert.location,
sonvininsert.area,
companysonvinunitvenue.venuename,
sonvininsert.venue,
sonvininsert.instructore,
instructoreexpense.amount
from
instructoreexpense
left outer join sonvininsert on
sonvininsert.sonvinid=instructoreexpense.sonvinid and
sonvininsert.status='0'
left outer join finalinstructoreexpense on
finalinstructoreexpense.sonvinid=instructoreexpense.sonvinid
left outer join companysonvinunitvenue on
companysonvinunitvenue.id=sonvininsert.comsonvinid
where
sonvininsert.sonvinid not in(select sonvinid from listinvoice)
and
sonvininsert.date
between convert(datetime,@from,105) and
convert(datetime,@to,105) and
sonvininsert.trainer=(select empname from trainerdetails where trid=@trainer)
and instructoreexpense.sonvinid NOT IN (
SELECT CAST(Item AS INTEGER)
FROM SplitString(@sonvinid, ',')
)
order by instructoreexpense.sonvinid
end
end
现在一切正常,现在在这条线上
insert into listinvoice(sonvinid,tid,date,brandname,zone,location,area,venuename,venue,instructore,amount)
我想添加bill_id
我将从我程序中的文本框中获取我的bill_id
所以我想把这一行改成这样
insert into listinvoice(sonvinid,tid,date,brandname,zone,location,area,venuename,venue,instructore,amount,bill_id=@bill_id)
但我发现了
的错误Msg 102, Level 15, State 1, Procedure profinalinstexpensesonid, Line 14 Incorrect syntax near '='.
我需要做什么,
我正在从我的文本框中获取 bill_id,
还有其他选择吗???
问题出在您的 INSERT
语句上:
insert into listinvoice(sonvinid,tid,date,brandname,zone,
location,area,venuename,venue,instructore,amount,bill_id=@bill_id)
您还没有完成声明。您通常会像这样格式化它:
INSERT INTO (Col1, Col2, Col3) VALUES (@Val1, @Val2, @Val3)
您将首先在第一组中列出要为其提供值的列,然后在关键字 VALUES
之后的第二组中列出值本身。
在您的列表中,您似乎列出了要插入的列,但最后一列除外,您还试图在其中以某种方式分配一个值。你需要这样的东西:
insert into listinvoice(sonvinid,tid,date,brandname,zone,
location,area,venuename,venue,instructore,amount,bill_id)
VALUES (@sonvinid, ..., @bill_id)
显然,您需要将省略号替换为您的实际参数。
你必须改变你的说法。您目前正在这样做:
insert into listinvoice(sonvinid,tid,date,brandname,zone,location,area,venuename,venue,instructore,amount,bill_id=@bill_id)
应该是这样的:
insert into listinvoice(sonvinid,tid,date,brandname,zone,location,area,venuename,venue,instructore,amount,bill_id)
select
instructoreexpense.sonvinid,
sonvininsert.trainer,
convert(varchar,sonvininsert.date,105) as date ,
sonvininsert.brandname,
substring(sonvininsert.zone,1,1)as zone,
sonvininsert.location,
sonvininsert.area,
companysonvinunitvenue.venuename,
sonvininsert.venue,
sonvininsert.instructore,
instructoreexpense.amount,
@bill_id
from
instructoreexpense
left outer join sonvininsert on
sonvininsert.sonvinid=instructoreexpense.sonvinid and
sonvininsert.status='0'
left outer join finalinstructoreexpense on
finalinstructoreexpense.sonvinid=instructoreexpense.sonvinid
left outer join companysonvinunitvenue on
companysonvinunitvenue.id=sonvininsert.comsonvinid
where
sonvininsert.sonvinid not in(select sonvinid from listinvoice)
and
sonvininsert.date
between convert(datetime,@from,105) and
convert(datetime,@to,105) and
sonvininsert.trainer=(select empname from trainerdetails where trid=@trainer)
and instructoreexpense.sonvinid NOT IN (
SELECT CAST(Item AS INTEGER)
FROM SplitString(@sonvinid, ',')
)
order by instructoreexpense.sonvinid