Click here to Skip to main content
15,904,638 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Alias name A is not accepting in a query ,though the query is running fiune in Sqlserver


Error Message----Incorrect syntax near 'A'

C#
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;
        }
Posted
Updated 4-Mar-13 2:54am
v4

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.
 
Share this answer
 
Comments
sr_24 4-Mar-13 8:34am    
its difficult to show the format here but i have maintained proper spaces
I am already using Concatenator "+" i have increased space between Table name and alias name ...but same error is repeating ... Incorrect syntax near 'A'.
MalwareTrojan 5-Mar-13 1:16am    
Show me your latest Query.
I think you forgot to put space :-
this is your code:
C#
B.Keyword4OR A.SelectedKeyword= B.Keyword5 OR A.SelectedKeyword = B.Keyword6OR A.SelectedKeyword = B.Keyword7"

check B.Keyword6OR, it should be written like B.Keyword6 OR .

here is updated code:
C#
 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.
 
Share this answer
 
Comments
sr_24 4-Mar-13 8:33am    
I am already using Concatenator "+"
i have increased space between Table name and alias name ...but same error is repeating ...
Incorrect syntax near 'A'.
Raje_ 4-Mar-13 8:43am    
Can you post your all column name of both tables?
sr_24 4-Mar-13 8:51am    
these are the columns -- Raje_


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
Raje_ 4-Mar-13 9:04am    
Here in first table your third column name is Selectedkeyword (k is in lower case), but in your codebehind code it is SelectedKeyword (k is in upper case). and also make sure that DataType of both the columns Selectedkeyword and keyword.. are same.
sr_24 4-Mar-13 9:24am    
i resolved thew error ,though i was using + concatenator in the Query i was passing ,but some thing was though wrong , now i hv removed all + and it worked ...thanks for ur help bro Raje_

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900