All problems that may occur in static SQL code may, in fact, also occur in dynamic SQL. Static SQL code is automatically translated by the SSMA tool; all dynamic SQL code must be written manually. So, in theory, dynamic SQL involves more work, but in practice, dynamic SQL is relatively simple. In the standard version, the following problems were encountered, which were discussed in Appendix A, Appendix B and Appendix C.
Example:
Old code: |
|
New code: |
|
DateDiff()
calls to ssma_datediff()
emulation function calls.DatePart()
calls to ssma_datepart()
emulation function calls.DateAdd(cwk, …)
or DateAdd(calweekofyear, …)
function call by the DateAdd(wk, …)
function call and replace the DateAdd(cdw, …)
or DateAdd(caldayofweek, …)
function call by the DateAdd(dw, …)
function call.DataLength()
function for char, varchar and text fields, use the LEN()
function.CharLength()
function, use the LEN()
function.Warning: The ASE LEN()
function takes into account trailing spaces, but the MS SQL Server LEN()
function does not. If you want to include trailing spaces, use the char_length_nvarchar()
emulation function.
IS NULL
and IS NOT NULL
.Because the OLEDB and ODBC drivers themselves send a default connection string, the programming code used for comparisons with NULL
should be as defensive as possible. The default is ANSI_NULLS = ON
. Using a search and replace operation on the files, the following changes can be made:
Old code |
New code |
x = NULL |
x IS NULL |
x <> NULL |
x IS NOT NULL |
x != NULL |
x IS NOT NULL |
NULL = x |
x IS NULL |
NULL <> x |
x IS NOT NULL |
NULL != x |
x IS NOT NULL |
The first conversion (= NULL
to IS NULL
) cannot take place automatically. For the conversions <> NULL
and != NULL
, you can perform a search and replace operation in the files. This needs to be done first, because the = NULL
pattern is also part of the !=NULL
pattern. This method will result in fewer remaining items to check. In MS SQL, the NULL IS [NOT] x
construct is not allowed and must be rewritten to x IS [NOT] NULL
, which must also be done manually.
Char
to NChar
.VarChar
to NVarChar
.Text
to NVarChar(max)
.Image
to VarBinary(max)
.DateTime
to DateTime2(3)
.*=
and =*
) to the ANSI join syntax (LEFT OUTER JOIN
and RIGHT OUTER JOIN
).RTRIM
to the right-hand argument of a LIKE
operator.