SSRS - SQL Syntax

Hello,

Anyone able to point out where i’ve gone wrong?

I just keep getting

Incorrect syntax near 'T1'.
Incorrect syntax near 'T2'.
="SELECT
    T1.PackNum,
    T1.PackLine,
    T1.LineDesc,
    T2.SerialNumber,
    T1.KitParentLine,
    T1.PartNum
FROM ShipDtl_" + Parameters!TableGuid.Value + " T1 
INNER JOIN (
    SELECT DISTINCT 
        T5.PackNum,
        T5.PackLine, 
        T5.PartNum,
        T5.LineDesc,
        T3.SerialNumber,
        T5.KitParentLine
    FROM ShipDtl_" + Parameters!TableGuid.Value + " T5
    INNER JOIN SerialNo_" + Parameters!TableGuid.Value + " T3 ON
        T5.Company = T3.Company
        AND T5.PackNum = T3.PackNum
        AND T5.PackLine = T3.PackLine
) T2 ON
    T1.PackNum = T2.PackNum
    AND T1.KitParentLine = T2.PackLine"

Use single quotes within the statement.

Confused Kevin James GIF by TV Land

I don’t think the problem is in your SQL but maybe the report’s references to the fields. When I put your code into SQL directly, it works just fine.

1 Like

:confused: I’ll try that.

Make sure there is a space after the line feeds. Pasted into SSMS it works, but for reporting services it doesn’t seem to.

What do you mean line feeds?

What you see from your pasted code up top (I put in a <LINEFEED> for where it goes to the new line

FROM ShipDtl_" + Parameters!TableGuid.Value + " T1<LINEFEED>
INNER JOIN (

Based on my experience … this is how I think the report builder interprets it:

FROM ShipDtl_" + Parameters!TableGuid.Value + " T1INNER JOIN (

Notice, no space between the T1 and INNER

3 Likes