我的sql语句出现语法错误 [英] Syntax error with my sql statement

查看:146
本文介绍了我的sql语句出现语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好所有



我在这些sql语句旁边面临一条错误信息,所以你能以正确的方式写下来帮助我吗? !错误消息是:关键字'AND'附近的语法不正确。



Hello all

I am facing an error message next to those sql statement , so can you please help me by writing it in a correct way that can be work! an errors message is: Incorrect syntax near the keyword 'AND'.

@"SELECT JobNum, Dept, PubDate, EndDate, Employer,VacCountry, VacState, 
VacCity, Jobtitle, CompLogo, Wtag, SUBSTRING(jobdesc,1,40) as jobdesc FROM jobs WHERE VacCountry = @Location and CHARINDEX(@Wtags, Wtag)>0 ORDER BY PubDate DESC;







string query = @"SELECT UID, Country, State, City, Wtag,Logo, Website, UsrType, BizCateg, BizSubCateg, Twitter, GooglePlus,Facebook, CompNme,SUBSTRING([CompDesc],1,40) as CompDesc From UserInfo where Country = @Location and UsrType = 'Business' and CHARINDEX(@Wtag, Wtag)>0 ORDER BY [RegDate] DESC";

推荐答案

首先尝试在sql server中单独调试你的查询(如果sql server是你的你的查询程序)。并尝试将直接值传递给@location和@Wtag变量。

1.如果您能够成功运行查询,那么您可能会从页面传递错误的参数作为动态查询。



2 。如果你无法从查询程序运行查询,那么尝试在没有WHERE子句的情况下运行它,并逐个添加你的条款,你可以成功运行你的查询。



你的写作语法没有错。你的变量赋值有问题。
First try to debug your query separately in your sql server (If sql server is your query program). And try to pass direct value to @location and @Wtag variables.
1. If you are able to run query successfully then chances are you are passing wrong parameters from your page as dynamic query.

2.If you are not able to run query from your query program then try to run it without WHERE clause and one by one add your clauses upto which you can run your query successfully.

There is nothing wrong with the syntax your writing. something wrong with your variable assignment.


这篇关于我的sql语句出现语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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