web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Problem creating a SSRS report - SQL statement not working

(0) ShareShare
ReportReport
Posted on by 790

I am trying build a report using SRS.  I am creating a DataTable using a SQL statement.  The SQL after the "if" works but the SQL after the "else" returns no rows.  Here is the code in my DataMethod:

 

 

 

 

 

 

 

 

 

 

 

 

 

public partial class WFSPackingLists
{

    [AxSessionPermission(SecurityAction.Assert)]   
    [DataMethod(), AxSessionPermission(SecurityAction.Assert)]
    public static DataTable GetPackingLists(string PackingListsDS_SalesOrder)
    {
        DataSet ds;

        if (PackingListsDS_SalesOrder == "*")
        {
            ds = SqlHelper.ExecuteDataset("Server=wfssqlsrv01;Database=AX2009_Carib_Dev;Integrated Security=SSPI",
                                          CommandType.Text, @"SELECT TransRefID, InvoiceID, PackingSlipID, COUNT(1) OVER (PARTITION BY TransRefID) as 'Item Count', StatusIssue, DatePhysical, Qty, COSTAMOUNTPOSTED, DateFinancial, DataareaID
                                      FROM inventtrans WHERE transtype = 0 AND Transrefid > 'SC00000000'
                                      AND packingslipID > 'PS000000' AND StatusIssue IN (1, 2)
                                      ORDER BY TransrefID");
        }
        else
        {
            ds = SqlHelper.ExecuteDataset("Server=wfssqlsrv01;Database=AX2009_Carib_Dev;Integrated Security=SSPI",
                                          CommandType.Text, @"SELECT TransRefID, InvoiceID, PackingSlipID, COUNT(1) OVER (PARTITION BY TransRefID) as 'Item Count', StatusIssue, DatePhysical, Qty, COSTAMOUNTPOSTED, DateFinancial, DataareaID
                                      FROM inventtrans WHERE transtype = 0 AND Transrefid > 'SC00000000'
                                      AND packingslipID > 'PS000000' AND StatusIssue IN (1, 2)
                                      AND TransrefID = ' + PackingListsDS_SalesOrder + '
                                      ORDER BY TransrefID");
        }
        return ds.Tables[0];
    } 
   
}

The first SQL statement works if I use "*" as my parameter value.  But the SQL statement after the "else" never returns anything.  I am entering a valid TransrefID.  Not sure if it is a problem with my single quotes or the parameter.  Can anyone help?

Thanks,

Bob

 

 

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Brandon Wiese Profile Picture
    17,788 on at

    You are not correctly inserting the value of PackingListsDS_SalesOrder into your SQL Statement.  Instead, you are literately searching for the value ' + PackingListsDS_SalesOrder + '

    Try

    AND TransrefID = (single quote)(double quote) + PackingListsDS_SalesOrder + (double quote)(single quote)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans