SQL incorrect syntax near '('.

sylvia 1 Reputation point
2022-10-11T10:24:55.793+00:00

So my query looks like this
select
tbl_3_1_PolygonDetails.(Pit)+ '_'+(SHOTID)
as BlastName
,tbl_3_1_PolygonDetails.SUBSTRING ( (Pit)+ ''+(SHOTID), 1 , LEN((Pit)+ ''+(SHOTID))-1 ) Blast_ID
,tbl_3_1_PolygonDetails.Load_Date from tbl_3_1_PolygonDetails right join tbl_2_1_WencoData
on
tbl_3_1_PolygonDetails.SUBSTRING ( (Pit)+ ''+(SHOTID), 1 , LEN((Pit)+ ''+(SHOTID) -1 ) Blast_ID=tbl_2_1_WencoData.Blast_ID

Developer technologies Transact-SQL
SQL Server Other
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Olaf Helper 47,436 Reputation points
    2022-10-11T10:29:01.907+00:00

    So my query looks like this
    tbl_3_1_PolygonDetails.(Pit)

    Is (Pit) really the column name, including round brackets ( ) ? The you have to set the column name in square brackest [ ] to get a valid object qualifier like

    select tbl_3_1_PolygonDetails.[(Pit)]  
    

    Better don't use special characters for object names.

    1 person found this answer helpful.

  2. Tom Phillips 17,771 Reputation points
    2022-10-11T13:31:21.383+00:00

    What you posted is not valid Microsoft TSQL statements. You cannot surround column names with () in TSQL or ANSI SQL.


  3. NikoXu-msft 1,916 Reputation points
    2022-10-12T03:12:18.703+00:00

    Hi @sylvia ,

    Try this code:

    select  
    tbl_3_1_PolygonDetails.Pit+ ''+SHOTID  
    as BlastName  
    ,SUBSTRING(tbl_3_1_PolygonDetails. Pit+ ''+SHOTID, 1 , LEN(Pit+ ''+SHOTID)-1 ) Blast_ID  
    ,tbl_3_1_PolygonDetails.Load_Date from tbl_3_1_PolygonDetails right join tbl_2_1_WencoData  
    on  
    SUBSTRING(tbl_3_1_PolygonDetails.  Pit+ ''+SHOTID, 1 , LEN(Pit+ '_'+SHOTID) -1 ) =tbl_2_1_WencoData.Blast_ID  
    

    Best regards
    Niko

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.