Friday, September 28, 2012

Sybase to SQL Server Migration Issues

Variable Scope/behavior in Update statment:

                   In Sybase intermediate calculation with variable for the update statement,Variable value is based on last executed statement or last executed record.In Sybase,variable updation will happen after the column updation.Which means the updation in variable has low priority when compare with the updation in column  for the single update statement.If we think the output of the updated variable want to become the input of the column updation for each and every row,we cannot attain in Sybase.Because the update in column will execute first and then update in variable execute in single update statement even we placed left or right side.

But in SQL Server we can perform the above operation.The variables are highly dynamic and record dependent.The priority for the variable updation is in high priority.So we can get consistent result.

If you see the below given screenshots you can understand the scenario
which i am trying to explain.

Variable behavior in Sybase Update statement




Variable behavior in SQL Server Update statement


































             I just shared the difference between two technologies for the update statement while using intermediate variable.Hopefully we won't get such a scenario from Source.




















Please click here to know about sybase to sql server migration issues 

Sybase to SQL Server Migration Issues

Data truncation while Insertion

                 The behavior of Sybase and SQL Server is different in the Insert statement.
When we trying to insert additional characters when compare with actual column length,
Sybase automatically truncates the excess characters and inserts.
But SQL Server will raises the below given error. 

Msg 8152, Level 16, State 14, Line 2
String or binary data would be truncated.
The statement has been terminated.

                 If we are trying to insert the more than 10 character for the column which is having
length 10,Sybase will removes the characters from 11th position and inserts the first 10 character
into the table.But SQL Server raises the error.You can understand easily with the
following Screenshots given below.

Sybase,Inserting too many characters than actual column length
  
SQL Server,Inserting too many characters than actual column length




























Please click here to know about sybase to sql server migration issues 

Sybase to SQL Server Migration Issues

 Default Date/Datetime format in Sybase Vs SQL Server:

               Default Date/Datetime Format is different for both Sybase and SQL Server.
So we need to change the target system’s(SQL Server) date/datetime format,
based on the source system’s output.I am giving the default datetime formats below.

Sybase Default Date Format:
              MON DD YYYY H: HH:MM: SSS AM

SQL Server Default Date Format:
              YYYY-MM-DD HH:MM:SS

Please click here to know about sybase to sql server migration issues

Thursday, September 27, 2012

Cursor behavior in SQL Server vs Sybase


Objective is to be, if one cursor’s input is based on the other cursor. We should execute the input cursor with prior and input cursor’s script want to come first in the procedure
Cursor interdependency based on parameter supported by Sybase, even the inner cursors declare statement placed next of the outer cursors declare statement. But Cursor interdependency based on parameter not supported in SQL server, if the Cursor declaration is not done inside the outer cursor’s open statement. We will get the different result set for the same logic code based on the Sybase and SQL Server. If we made the code changes to declare the Inner cursor inside the Outer cursor (between Open and close block), we can get the same result set. I have given detailed explanation below along with screenshot.

Sybase Script with Cursor Inter-dependency



















Here first cursors output is the input for the second cursor. But the declaration of the second cursor located before the first cursors open statement. Though Sybase maintains the Inter-dependency between the cursor and passes the first cursor’s output to next cursor’s input. So the Sybase output is based on the two cursor’s input and output. You can see the output of the Sybase below.
One more is, Cursor de-allocation handled by Sybase engine automatically. But In SQL Server we should give the de-allocation explicitly for the required places.

Sybase Output for the above given sample code


















To achieve the same result set in SQL Server we should declare the Second (Inner) Cursor declaration and open statement inside the First (Outer) Cursor’s Open statement. Otherwise SQL Server engine will gives the NULL value for the @var2 and only give the below result set.

SQL Server output with bug 










SQL Server Script with relevant changes 















Here we given De-allocate statement for each cursor explicitly for the required places .Outer cursors output will simply flow as a inner cursor’s input. If we made the code changes like above we can get the same result as like as Sybase. Once again I attached actual result for your reference.

SQL Server Output with relevant changes 































Please click here to know about sybase to sql server migration issues 

SSMA error message S2SS0015


Unparsed SQL [ZERO:] cannot be converted:

               SSMA raises above given error, while migrating the 'GOTO' Transact sql.
Though SSMA raises the error,both Sybase and SQL Server will get execute the code successfully along with GOTO.To maintain the best practice,readability we should convert the 'GOTO' Control statement into IF....ELSE,Nested IF or any other Control statement.I have placed sample code with GOTO Statement along with the output.


Below given sample code will give the same result without GOTO to follow best practice.Try to avoid GOTO statement in the program.


Please click here to know about sybase to sql server migration issues

Missing parameter in procedure call

Expects Parameter in the procedure call:

                 While calling procedure,Sybase adding NULL for the required parameters and executed successfully, even we miss to pass some parameters .But the SQL Server raises the error while missing to pass some parameters.
                     If we are passing 2 parameter while calling the 'dbo.calledproc' instead of 3 actual parameter,Sybase engine adds NULL for the third parameter.But SQL Server raises the below error.
Msg 201, Level 16, State 4, Procedure CALLED_PROC, Line 0
Procedure or function 'CALLED_PROC' expects parameter '@PARAMETER3', which was not supplied.


SQL Server Result wihile missing parameter in procedure call


To avoid the above given error,we should add NULL for remaining parameters for procedure call.Then the proceudre will get executed succussfully.Find the correct screenshot below.


Please click here to know about sybase to sql server migration issues

Passing Excess parameter in procedure call

Passing additional parameter in the procedure call:

                      While calling procedure,Sybase passes only required parameters and executed successfully, even we pass the too many parameters .But the SQL Server raises the error while passing too many parameter.
                     If we are passing 4 parameter while calling the 'dbo.calledproc' instead of 3 actual parameter,Sybase engine removes the fourth parameter and pass the first three parameter.But SQL Server raises the below error.

Msg 8144, Level 16, State 2, Procedure CALLED_PROC, Line 0
Procedure or function CALLED_PROC has too many arguments specified.

SQL Server Result while passing Excess parameter

To avoid the above given error,we should remove the additional/unwanted parameters from procedure call.Then the proceudre will get executed succussfully.Find the correct screenshot below. 
      .

Please click here to know about sybase to sql server migration issues

Wednesday, September 26, 2012

SSMA error message S2SS0015

Unparsed SQL, cannot converted

 Please Check the Script to satisfy the following best practices to avoid the S2SS0015 error message.
1.Required space should be there,in between column and sql server keywords.
2.Check wether,given keywords available in sql server.
3.Need to check,variable declaration is correct.
4.Check for syntax error.

INSERTINTO #temp_swtch
 (           column1,
             column2,
             column3)
       VALUES (
            'first value',
            'second value',
            1 )

In the above given statement,Space character missing between INSERT and INTO.
If we change the statement like below we can resolve the S2SS0015 Error.

INSERT INTO #temp_swtch
 (           column1,
             column2,
             column3)
       VALUES (
            'first value',
            'second value',
            1 )

Please click here to know about sybase to sql server migration issues

SSMA error message S2SS0002

The following SQL statement cannot be converted

CREATE TABLE tempdb.guest.temptable (
                                 user_id int NOT NULL,
                                 req_id int NOT NULL
                                                                 )
                                 LOCK  DATAROWS
LOCK  DATAROWS keyword is not available in sql server.
To achieve the same in sql server, we should give nolock for the select statments involving the above table  or else we should set the isolation level as 'Read uncommitted '.

Please click here to know about sybase to sql server migration issues

Monday, September 24, 2012

SSMA warning message S2SS0016

SQL Server might use a different error code
                        Error code may change based on the Sybase and SQL Server for the same error.But in some cases both are having same error code.
                        Selecting the error from @@error and Returning error code by @@error wont make any difference in both the technologies.And generic condition check also wont make any difference.That means
     IF @@ERROR=0
     IF @@ERROR<>0
Both statement behaves same in sybase and SQL Server.We dont need to make any change for the below statement also.
SELECT @@ERROR
RETURN @@ERROR

If the script contains specific error code condition.Then we should take care of the error.
Please use the below links to refer Sybase error codes and meaning.

http://infocenter.sybase.com/archive/index.jsp?topic=/com.sybase.infocenter.dc36584.1260/html/iqerror/Errsybcode.htm

http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.39996_1250/html/svrtsg/svrtsg382.htm

http://manuals.sybase.com/onlinebooks/group-asarc/srv10024/errtsg/@Generic__BookTextView/77

According to the Sybase error codes change the equivalent SQL Server error codes in the Code.

Please click here to know about sybase to sql server migration issues

SSMA informational message S2SS0069

The error number was ignored

                At that time of migration,SSMA will give the sybase equivalent error number and severity.
As per the error number and severity Application code should change.
               Other than the application changes,There is no much Database changes for RAISERROR.

Sample code given below:
      RAISERROR(@error_format_20, 16, 1)

Please click here to know about sybase to sql server migration issues

SSMA error message S2SS0075

Unable to convert Cursor error message

                    We cannot assign the value to the variable in cursor select statement,followed by the declaration of the cursor 
                    While assigning into variable in the cusrsor declaration leads to error.We can remove this assignment from declaration,because fetch statement should have the assignment for the output.Removal of this assignment wont create an issue.
                      I have placed sample cursor declaration with assignment along with corresponding error.

Cursor declaration with assignment





















Cursor declaration without assignment:

Cursor declaration without assignment
























We can use the above given screenshot to resolve S2SS0075.

Please click here to know about sybase to sql server migration issues

SSMA warning message S2SS0064

Possibility of mismatch in LIKE operator behavior

                    The behavior of Sybase and SQL Server deviating in some some extends.
Here i have given that exceptional scenarios and how to handle that scenarios.
Other than the wild card '%',sybase and sql server behaves same.
So we need to take care of the wild card '%'.

                   If the key string has spaces in trailing position,Sybase automatically right trimming the Key string and search from the searching string only reach the end of the string.That means if the searching start position in the Target string is greater than the key string length from right to left,Sybase and SQL Server behaves same.If the Searching start position in the Target string is less than the key string length from right to left,Sybase right trimming key string and search but not SQL Server.
                  
                   To get the better understanding i given the examples below.
                                                            
Sybase like Observation


SQL Server like observation


Above given screenshots will help to understands the behavior of the Sybase and SQL Server for the usage of Like operator.To get the first row output in the sybase,keystring right trimmed and then searched.But in SQL Server space also taken as a character,so that we are getting only one record.To resolve this difference.Please follow the below changes.

SQL Server resolved like observation
Now the output will be same in both Sybase and SQL Server.

Please click here to know about sybase to sql server migration issues

SSMA error message S2SS0044

Complex expression cannot be used as OUTPUT parameter in EXECUTE Statement

             To avoid this S2SS0044 Error,We should avoid the following scenarios given below:
1.Dont perform calculation,while passing parameter.
2.Dont place brackets on variables of OUTPUT parameter.
3.Dont place constants for OUTPUT parameter

Kindly execute the below test quieries to simulate yourself.
--Create sample procedure
CREATE PROCEDURE dbo.test_proc(@a INT,@b INT OUTPUT)
AS
BEGIN
  SELECT
'HI'

END

--Case1
EXEC dbo.test_proc 1,2 OUTPUT

Msg 179, Level 15, State 1, Line 1
Cannot use the OUTPUT option when passing a constant to a stored procedure.

--Case2

DECLARE @x INT
EXEC
dbo.test_proc 1,[@x] OUTPUT

Msg 179, Level 15, State 1, Line 3
Cannot use the OUTPUT option when passing a constant to a stored procedure.


This S2SS0044 will leads to runtime Error.We can resolve,by removing brackets of the OUTPUT variable or avoiding constant in OUTPUT parameter.

Sample execute statement for the successful Run.
DECLARE @x INT
EXEC
dbo.test_proc 1,@x OUTPUT

Please click here to know about sybase to sql server migration issues

Thursday, September 20, 2012

NULL Handling in IF Condition

            Sometime, SQL Server gives the different result in the ‘if’ condition for the same input. 
I am given here the complete observation of IF Condition.
Those test results and possibilities given below.
‘Yes’ indicates ‘if’ condition pass.
‘No’ indicates ‘if’ condition fails.
Possibilities:
1.@var =null                                                                       Sybase/SQL Server
                Null=null                                                              -Yes/No                             -IS NULL
                Val=null                                                               -No/No                              -IS NULL
Instead of ‘@var = NULL, we should give @var IS NULL.
2.@var <> null
                Null<>null                                                           -No/No                              -IS NOT NULL
                Val<>null                                                            -Yes/No                             -IS NOT NULL
Instead of ‘@var <> NULL, we should give @var IS NOT NULL.
3.@var =’constant’ (If the constant will be only Varchar/char)
                1. Null =constant                                              -No/No                                -ISNULL
2. Not null (Same value)                =’constant’     -Yes/Yes                             -ISNULL
Instead of @var =’constant’, we should give ISNULL (@var,’’) =’constant’
4.@var <> ’constant     
                1. Null<>constant                                            -Yes/No                               -ISNULL
2. Value (Same value) <>constant                      -No/No                                -ISNULL
Instead of @var <> ’constant’, we should give ISNULL (@var,’’) <>’constant’
5. Constant=null                                                               -No/No                                -IS NULL
6. Constant<> null                                                           -Yes/No                               -IS NOT NULL
7.@var = or <> @var                                                       -Above six will cover this. So we need to add ISNULL.

 CASE 1:
declare @variable varchar (30)
if (@variable <> '1')
select 'Yes'
else
select  'No'
Sybase output              :’Yes’
Sql server output           :’No’
After the Conversion from Sybase to SQL Server,at that time of Unit testing we should take care of this
issue.Changes can be like below.The substitute string in the ISNULL,cant be equal to the right side string.
How to resolve?:
declare @variable varchar (30)
if (ISNULL(@variable,'') <> '1')
select 'Yes'
else
select  'No'
The output will be ‘Yes’.

CASE 2:
declare @variable int
if (@variable <> '1')
select 'Yes'
else
select  'No'
Sybase output              :Implicit conversion from data type ‘varchar’ to ‘ int’ is not allowed.
Sql server Output          :’No’ 
How to resolve?:
declare @ variable int
if (@variable <> 1)
select 'Yes'
else
select  'No'
The code will get executed without error and gives ‘Yes’ as output.
This scenario, wont make any issue.Because from Sybase itself raise the error,if the data type is different.
Please don’t add isnull() blindly for all the comparision.

CASE 3:
declare @variable varchar(30)
if (@variable <> null)
select 'Yes'
else
select  'No'
Sybase output              :’No’
Sql server output           :’No’ 
How to resolve?:
declare @variable varchar(30)
if (@variable is not null)
select 'Yes'
else
select  'No'
The output for the above code is ‘No’.But we should change as ANSII standard.

CASE 4:
declare @variable varchar(30)
if (@variable = null)
select 'Yes'
else
select  'No'
Sybase output              :’Yes’
Sql server output           :’No’ 
How to resolve?:
declare @ variable varchar(30)
if (@variable is null)
select 'Yes'
else
select  'No'
The output for the above code is ‘Yes’.But we should change as ANSII standard.

CASE 5:
declare @variable1 varchar(30)
declare @variable2 varchar(30)
if (@variable1 = @variable2)
select 'Yes'
else
select  'No'
Sybase output              :The output for the condition is based on the different input for the variables.
            We can predict the output based on the above four Cases.
Sql server output           :Output will be based on the above four cases.So we should add the ISNULL in both the variables. 
How to resolve?:
declare @variable1 varchar(30)
declare @variable2 varchar(30)
if (ISNULL(@variable1,'') = ISNULL(@variable2,''))
select 'Yes'
else
select  'No'
The output will be based on the above four cases.If we add the ISNULL In the variable,we can avoid the wrong output.
            Initially I thought sybase will behave same manner in both, if condition and where clause for the 2 exception scenario’s given below.Finally I realised that,execution and output generation for the ‘if condition’ and ‘where clause will be different.
            In case of where clause,sybase executing same as like sql serverJJ.Here I am meaning that,both are neglecting null value comparision in the table where clause.Please view the detailed explanation below.
            The above given first and fifth case is applicable varchar data type.If we use the integer variable,which will create the functionality issue.The comparision input is string variable,we should give the alternate value for the ISNULL function.If the input is integer data type,please avoid for changing the code with isnull().Adding isnull() for all if statement will leads to headache. 
Table level Where clause behaviour
Sybase:
Case 1 for where clause:
If we execute the below select statement,
select   * from dbo.table where column1 (null value)=column2(null value)  
and column3=50
            I am getting 0 record,though there was a record for column3=50 and both the columns column1, column2 has null value.Which means sybase not comparing the null value in where clause.
Case 2 for where clause:
If we execute the below select statement,
select   * from dbo.table where column1(some value)<> column2 (null value)
 and column3 =50
I am getting 0 record,though there was a record for column3 =50 .One more is column column2 has null value and column1 has not null value.Which means means sybase not comparing the null value in where clause.
Sql server:
Case 1 for where clause:
If we execute the below select statement,
select   * from dbo.table where coloumn1 (null value)=column2(null value)  
and column3=50
            I am getting 0 record,though there was a record for column3 =50 and both the columns column1, column2 has null value.Which means sql server not comparing the null value in where clause. 
Case 2 for where clause:
If we execute the below select statement,
select   * from dbo.table where column1(some value)<>column2(null value)
 and column3=50
I am getting 0 record,though there was a record for column3=50 .One more is, column column2 has null value and column1 has not null value.Which means sql server not comparing null values in where clause.
Conclusion:
            We can neglect the ‘where’ clause comparision.We don’t need to modify in where
clause.Because Sybase and SQL Server are neglecting records which is having null comparision

in where clause.But we should take care for the ‘If condition’ for four different Cases given above.

That is Case1,Case 3,Case 4,Case 5.

Please click here to know about sybase to sql server migration issues