Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何在select语句vb.net中定义变量?_Sql - Fatal编程技术网

Sql 如何在select语句vb.net中定义变量?

Sql 如何在select语句vb.net中定义变量?,sql,Sql,我有一个这样的问题 Dim view_src_14作为字符串=GetParameterValue(“ViewSrc14”) Dim calendar_date_14作为字符串=GetParameterValue(“CalendarDate14”) calendar\u date\u 14和view\u src\u 14是变量。。。运行查询时,会出现以下错误: 日期类型“”的输入语法无效 我在哪里做更改???我认为这还不够具体,无法给出答案,但评论太长了 "select calendar_date

我有一个这样的问题

Dim view_src_14作为字符串=GetParameterValue(“ViewSrc14”)

Dim calendar_date_14作为字符串=GetParameterValue(“CalendarDate14”)

calendar\u date\u 14
view\u src\u 14
是变量。。。运行查询时,会出现以下错误:

日期类型“”的输入语法无效


我在哪里做更改???

我认为这还不够具体,无法给出答案,但评论太长了

"select calendar_date, view_src, sum(effective) effective_total, 
sum(ineffective) ineffective_total 
from wrk_alert_effectiveness 
where calendar_date= '" + @CalendarDate + "' AND " +  @ViewSrc + " 
group by 1,2 
order by 1 desc;"
您正在尝试执行一条SQL语句,在该语句中传入常量的值。这是允许的,并且是SQL的一部分--使用参数。有两种类型的参数,命名参数和位置参数

select calendar_date, view_src,
       sum(effective) as effective_total, sum(ineffective) as ineffective_total 
from wrk_alert_effectiveness 
where calendar_date = @date1 and @date2
group by 1, 2 
order by 1 desc;
对于匿名参数,这些参数通常由
表示。有时命名的是冒号


确切的语法取决于您使用的数据库和应用程序接口。我的观点是,您应该了解参数以及如何使用它们。

通常您会使用
DECLARE
语句,但这看起来更像是在尝试将服务器端变量插入SQL语句。当您说
calendar\u date\u 14
view\u src\u 14
是变量时,您是指服务器端变量吗?像PHP或C#?您使用的是什么DBMS?欢迎使用StackOverflow!您正在使用哪些RDBMS?Mysql、sqlite、postgresql、mssql、oracle等?我使用的是vb.net…我需要的是在语句中包含“calendar\u date\u 14”的语法。“where calendar\u date=X和Y”-您的意思是使用“between”而不是“=”?您试图执行的确切SQL字符串是什么,用这些参数值填充的意思?参数是正确的想法,但不能连接到SQL语句中
select calendar_date, view_src,
       sum(effective) as effective_total, sum(ineffective) as ineffective_total 
from wrk_alert_effectiveness 
where calendar_date = @date1 and @date2
group by 1, 2 
order by 1 desc;