不接受Join的sqlserver查询表的别名 [英] Not accepting alias name of sqlserver query table for Join
本文介绍了不接受Join的sqlserver查询表的别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
别名A在查询中不接受,但查询在Sqlserver中运行fi $
错误消息--- - 'A'附近的语法不正确
Alias name A is not accepting in a query ,though the query is running fiune in Sqlserver
Error Message----Incorrect syntax near ''A''
string Query ="SELECT DISTINCT B.CreatedDate, B.JobTitle,B.Location FROM UserFeedSelection A INNER JOIN JobForm B ON A.SelectedKeyword = B.Keyword1 OR A.SelectedKeyword = B.Keyword2 OR A.SelectedKeyword = B.Keyword3 OR A.SelectedKeyword = B.Keyword4OR A.SelectedKeyword= B.Keyword5 OR A.SelectedKeyword = B.Keyword6OR A.SelectedKeyword = B.Keyword7"
where cloumns of both tables are like that
Table -UserFeedSelection--
User_Id JobFeed Selectedkeyword
Table -JobForm--
[Job_Id] [int] NOT NULL,
[Recruiter_id] [int] NULL,
[JobTitle] [varchar](100) NULL,
[Location] [varchar](50) NULL,
[Category] [varchar](50) NULL,
[MinExp] [varchar](20) NULL,
[MaxExp] [varchar](20) NULL,
[Body] [varchar](2000) NULL,
[Keyword1] [varchar](50) NULL,
[Keyword2] [varchar](50) NULL,
[Keyword3] [varchar](50) NULL,
[Keyword4] [varchar](50) NULL,
[Keyword5] [varchar](50) NULL,
[Keyword6] [varchar](50) NULL,
[Keyword7] [varchar](50) NULL,
[Investor1] [varchar](50) NULL,
[Investor2] [varchar](50) NULL,
[Investor3] [varchar](50) NULL,
[Investor4] [varchar](50) NULL,
[Investor5] [varchar](50) NULL,
[CreatedDate] [datetime] NULL
da.GetDataReader(Query);
//nd GetDataReader() method is in my Dataaccess Layer File
public Boolean GetDataReader(string strSql)
{
try
{
if (connection.State != System.Data.ConnectionState.Open)
connection.Open();
SqlCommand sqlCmd = new SqlCommand(strSql, connection);
sqlCmd.CommandType = CommandType.Text;
if (dataReader != null && dataReader.IsClosed == false)
dataReader.Close();
dataReader = null;
dataReader = sqlCmd.ExecuteReader();
}
catch (Exception ex)
{
HandleException.SendMail(ex);
return false;
}
finally
{
// if (connection.State == ConnectionState.Open)
// connection.Close();
}
return true;
}
推荐答案
在您的查询中;在OR空间应该存在之前,中心的第3行A.SelectedKeyword = B.Keyword4OR。在查询的最后一行有同样的错误。
In your Query; 3rd line in center "A.SelectedKeyword = B.Keyword4OR" before OR space should be there. Same mistake is there in the last line of query.
我想你忘了放空间: -
这是你的代码:
I think you forgot to put space :-
this is your code:
B.Keyword4OR A.SelectedKeyword= B.Keyword5 OR A.SelectedKeyword = B.Keyword6OR A.SelectedKeyword = B.Keyword7"
检查B.Keyword6OR,它应该写成B.Keyword6 OR。
这里是更新的代码:
check B.Keyword6OR, it should be written like B.Keyword6 OR .
here is updated code:
string Query ="SELECT DISTINCT B.CreatedDate
,B.JobTitle
,B.Location
FROM UserFeedSelection A
INNER JOIN JobForm B ON A.SelectedKeyword = B.Keyword1
OR A.SelectedKeyword = B.Keyword2
OR A.SelectedKeyword = B.Keyword3
OR A.SelectedKeyword = B.Keyword4
OR A.SelectedKeyword = B.Keyword5
OR A.SelectedKeyword = B.Keyword6
OR A.SelectedKeyword = B.Keyword7"
不要忘记把所有给定的刺痛放在一行或使用连接。
祝你好运。
don''t forget to put all given sting in one line or use Concatenation.
Good luck.
这篇关于不接受Join的sqlserver查询表的别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文