我的代码有什么不对吗? [英] what is wrong white my code?

查看:62
本文介绍了我的代码有什么不对吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了存储过程,在表中创建表并插入变量

但是当我尝试将变量放入
时我得到错误
可以有人告诉我什么我的代码错了吗?



i created store procedure that create table and insert variables in the table
but i get error when i try to put the variable in
can some one tell me what is wrong white my code?

ALTER PROC [dbo].[SqldataTable2]
@tabelname nvarchar(50),
@id real,
@prod nvarchar(50),
@category varchar(50),
@price real,
@instock bit,
@count real,
@DateUpdate datetime,
@description nvarchar(max) 


as


   BEGIN
    
  
DECLARE @SQLString NVARCHAR(MAX)

 set @SQLString='
 

INSERT INTO '+@tabelname+' (ID,ProductName,Category,Price,Instock,[Count],DateUpdate,[Description])
VALUES (@id,@prod,@category,@price,@instock,@count,@DateUpdate,@description)
 
Select *from '+@tabelname+' 
order by ID Asc'
 EXEC (@SQLString)
 end;

-- and when i put a variable in the store procedure it tell:
-- "Must declare the scalar variable "@id"."
SqldataTable2 'dbo.DBT',66,'mazda','buty',786567,'true',88,'1978','buuu'

推荐答案

您还需要解析变量:



You need to parse in your variables as well:

'INSERT INTO '+@tabelname+' (ID,ProductName,Category,Price,Instock,[Count],DateUpdate,[Description])
VALUES (' + @id + ',...)'


你是上次询问随机表名称的那个人吗?你为什么做这个 ?以后命名的桌子是什么?为什么不能让一个表有一个额外的列,这表示系统当前在不同的表中表示什么?然后你可以写出理智,智能的代码。这是一团糟。
Are you the same person who asked about random table names last time ? Why are you doing this ? What are the tables named after ? Why can't you have the one table with an extra column, which denotes what is currently denoted in your system by different tables ? Then you can write sane, intelligent code. This is a mess.


这篇关于我的代码有什么不对吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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