Friday, September 13, 2019

SQL Server : Using named parameters in SQL Query

SQL Statement with named parameters

You can use named parameters :FromDate and :ToDate in your SQL Query to provide input for the fields "From Date" and "To Date" in udiMagic for uploading data from SQL Server to Tally ERP.

How to use parameters in SQL query?

Here's a sample SQL SELECT query that shows how to use the :FromDate and :ToDate named parameters

SELECT field1, field2, fldDate FROM table WHERE table.fldDate>=:FromDate AND table.fldDate<=:ToDate

Instead of hard-coding the period (from and to dates) in SQL-query, we have used 2 named parameters viz :FromDate and :ToDate. The values for these parameters are assigned at runtime based on the period you enter in the udiMagic screen.

1. In udiMagic screen, you must specify the FromDate and ToDate in dd/mm/yyyy format only.
2. The date format of SQL server  or your system may be different (ex: yyyy-mm-dd). However, udiMagic automatically sets the date format internally and hence there is no need to change your SQL Server / System date format.

No comments: