Sybase SQL Anywhere to SQL Server Migration

SQLines tools can help you transfer data, convert database schema (DDL), views, stored procedures, functions, triggers, queries and SQL scripts from SAP SQL Anywhere, Sybase SQL Anywhere, Sybase Adaptive Server Anywhere (Sybase ASA) to Microsoft SQL Server (MSSQL, MS SQL), Azure SQL Database, Azure Synapse.

Databases:

  • SAP Sybase SQL Anywhere 17, 16, 12, 11, 10, 9, 8, 7 and 5.x
  • Microsoft SQL Server 2022, 2019, 2017, 2016, 2014, 2012, 2008, 2005 and 2000, Azure SQL Database, Azure Synapse

See also Sybase Adaptive Server Enterprise to SQL Server Migration.

Migration Reference

Identifiers

Converting identifiers:

Sybase SQL Anywhere SQL Server
1 Constraint names are unique per table Constraint names are unique within a database more...
2 Default constraint name for a foreign key is the primary key table name Constraint, table names must be unique within a database more...

SQL Language Elements

Converting SQL and T/SQL language elements:

Sybase SQL Anywhere SQL Server
1 'a' + 'b' String concatenation 'a' + 'b'
2 // (Double slash) Single line comment -- (Double hyphen)
3 --
4 /* */ Multi-line comment /* */
5 IF condition THEN exp ELSE exp2 ENDIF IF expression CASE WHEN condition THEN exp ELSE exp2 END
6 SQLCODE Error code of last operation @@ERROR

Data Types

Converting numeric data types:

Sybase SQL Anywhere SQL Server
1 BIGINT 64-bit integer BIGINT
2 DECIMAL(p,s) Fixed point number DECIMAL(p,s)
3 DOUBLE [PRECISION] Double-precision floating-point number FLOAT
4 FLOAT(p) Floating-point number FLOAT(p)
5 INTEGER, INT 32-bit integer INTEGER, INT
6 MONEY Monetary data MONEY
7 NUMERIC(p,s) Fixed point number NUMERIC(p,s)
8 REAL Single-precision floating-point number REAL
9 SMALLINT 16-bit integer SMALLINT
10 SMALLMONEY Monetary data, ⇐ million currency units SMALLMONEY
11 TINYINT 8-bit unsigned integer, 0 to 255 TINYINT
12 UNSIGNED BIGINT 64-bit unsigned integer NUMERIC(20)
13 UNSIGNED INT 32-bit unsigned integer NUMERIC(10)
14 UNSIGNED SMALLINT 16-bit unsigned integer NUMERIC(5)
15 UNSIGNED TINYINT 8-bit unsigned integer, 0 to 255 TINYINT

Converting other data types:

Sybase SQL Anywhere SQL Server
1 BINARY(n) Variable-length binary string, 1 ⇐ n ⇐ 32767 VARBINARY(n)
2 BINARY VARYING(n) Variable-length binary string, 1 ⇐ n ⇐ 32767 VARBINARY(n)
3 BIT 0 or 1 value; NULL is not allowed BIT
4 BIT VARYING(n) Variable-length bit array, 1 ⇐ n ⇐ 32767 BINARY(n/8)
5 CHAR(n), CHARACTER(n) Variable-length string, not padded, 1 ⇐ n ⇐ 32767 VARCHAR(n)
6 DATE Date (year, month and day) DATE
7 DATETIME Date and time with fraction DATETIME2(6)
8 DATETIMEOFFSET Date and time with fraction and time zone DATETIMEOFFSET(6)
9 IMAGE Binary data, ⇐ 2G VARBINARY(max)
10 LONG BINARY Binary data, ⇐ 2G VARBINARY(max)
11 LONG BIT VARYING Bit array data, ⇐ 2G VARBINARY(max)
12 LONG NVARCHAR UTF-8 character data, ⇐ 2G NVARCHAR(max)
13 LONG VARBIT Bit array data, ⇐ 2G VARBINARY(max)
14 LONG VARCHAR Character data, ⇐ 2G VARCHAR(max)
15 NCHAR(n) Fixed-length UTF-8 string, 1 ⇐ n ⇐ 32767 NCHAR(n)
16 NTEXT UTF-8 character data, ⇐ 2G NVARCHAR(max)
17 NVARCHAR(n) Variable-length UTF-8 string, 1 ⇐ n ⇐ 32767 NVARCHAR(n)
18 SMALLDATETIME Date and time with fraction DATETIME2(6)
19 TEXT Character data, ⇐ 2G VARCHAR(max)
20 TIME Time (hour, minute, second and fraction) TIME(6)
21 TIMESTAMP Date and time with fraction DATETIME2(6)
22 TIMESTAMP WITH TIME ZONE Date and time with fraction and time zone DATETIMEOFFSET(6)
23 UNIQUEIDENTIFIER 16-byte GUID (UUID) data UNIQUEIDENTIFIER
24 UNIQUEIDENTIFIERSTR GUID (UUID) data in string format CHAR(36)
25 VARBINARY(n) Variable-length binary string, 1 ⇐ n ⇐ 32767 VARBINARY(n)
26 VARBIT(n) Variable-length bit array, 1 ⇐ n ⇐ 32767 BINARY(n/8)
27 VARCHAR(n) Variable-length string, 1 ⇐ n ⇐ 32767 VARCHAR(n) VARCHAR(max)
28 XML XML data XML

Built-in SQL Functions

Converting string functions:

Sybase SQL Anywhere SQL Server
1 ASCII(str) Get ASCII code of left-most char ASCII(str)
2 BYTE_LENGTH(string) Get length of string in bytes DATALENGTH(string)
3 BYTE_SUBSTR(string, start, len) Get a substring of string in bytes SUBSTRING(string, start, len)
4 CHAR(num) Get character from ASCII code CHAR(num)
5 CHAR_LENGTH(string) Get length of string in characters LEN(string)
6 CHARINDEX(substring, string) Get position of substring CHARINDEX(substring, string)
7 COMPARE(string, string2) Compare two character strings CASE expression
8 CONVERT(datatype, exp[, style]) Convert to another datatype CONVERT(datatype, exp[, style])
9 CSCONVERT(string, charset) Convert string between character sets
10 DATALENGTH(exp) Get length of exp in bytes DATALENGTH(exp)
11 INSERTSTR(position, str, str2) Insert str2 into str in specified position SUBSTRING and concatenation
12 LCASE(string) Lowercase string LOWER(string)
13 LEFT(string, n) Get n leftmost characters LEFT(string, n)
14 LENGTH(string), LEN(string) Get length of string in chars LEN(string)
15 LIST(string, del) Aggregate string concatenation STRING_AGG(string, del)
16 LOCATE(str, substring, start) Get position of substring CHARINDEX(substring, str, start)
17 LOWER(string) Lowercase string LOWER(string)
18 LTRIM(string) Remove leading spaces LTRIM(string)
19 NCHAR(integer) Convert Unicode code point to char NCHAR(integer)
20 PATINDEX(pattern, string) Get starting position of pattern PATINDEX(pattern, string)
21 REGEXP_SUBSTR(str, pattern) Get a substring of str using regexp
22 REPEAT(string, n) Repeat string n times REPLICATE(string, n)
23 REPLACE(str, search, replace) Replace search-string REPLACE(str, search, replace)
24 REPLICATE(string, n) Repeat string n times REPLICATE(string, n)
25 REVERSE(string) Get reverse string REVERSE(string)
26 RIGHT(string, n) Get n rightmost characters RIGHT(string, n)
27 RTRIM(string) Remove trailing spaces RTRIM(string)
28 SPACE(integer) Get string of spaces RPAD(' ', integer)
29 STR(numeric) Get string equivalent of a number STR(numeric)
30 STRING(str, str2, …) Concatenates strings CONCAT(str, str2, …)
31 STUFF(exp, start, len, rep) Replace characters in string STUFF(exp, start, len, rep)
32 SUBSTRING(string, pos, len) Get a substring of string SUBSTRING(string, pos, len)
33 SUBSTR(string, pos, len)
34 TO_CHAR(exp) Convert to string CONVERT(VARCHAR, exp)
35 TO_NCHAR(exp) Convert to NCHAR CONVERT(NCHAR, exp)
36 TRIM(string) Remove leading and trailing spaces RTRIM(LTRIM(string))
37 UCASE(string) Uppercase string UPPER(string)
38 UNICODE(string) Get Unicode code of the 1st character UNICODE(string)
39 UNISTR(string) Convert Unicode code points to chars Expressions using NCHAR
40 UPPER(string) Uppercase string UPPER(string)

Converting other functions:

Sybase SQL Anywhere SQL Server
1 ABS(num) Get the absolute value ABS(num)
2 ACOS(num) Get the arc cosine ACOS(num)
3 ARGN(position, exp, exp2, …) Get selected argument from list CASE expression
4 ASIN(num) Get the arc sine ASIN(num)
5 ATAN(num) Get the arc tangent ATAN(num)
6 ATAN2(x, y) Get the arc tangent of x and y ATN2(x, y)
7 BASE64_DECODE(base64_str) MIME base64 decoding User-defined function
8 BASE64_ENCODE(str) MIME base64 encoding User-defined function
9 BIT_LENGTH(bit_str) Get length of bit_str in bits LEN(bit_str) * 8
10 BIT_SUBSTR(bit_str, start, len) Get a substring of bit_str SUBSTRING(bit_str, start, len)
11 CEILING(num) Get the smallest following integer CEILING(num)
CEIL(num)
12 COALESCE(exp1, exp2, …) Return first non-NULL expression COALESCE(exp1, exp2, …)
13 CONVERT(datatype, exp[, style]) Convert to another datatype CONVERT(datatype, exp[, style])
14 COS(num) Get the cosine COS(num)
15 COT(num) Get the cotangent COT(num)
16 CURRENT DATE Get the current date CONVERT(DATE, GETDATE())
17 CURRENT TIME Get the current time CONVERT(TIME, GETDATE())
18 CURRENT TIMESTAMP Get the current date and time GETDATE()
CURRENT_TIMESTAMP
19 CURRENT USER Get the authenticated user name SYSTEM_USER
CURRENT_USER
20 DATE(datetime) Extract date from datetime CONVERT(DATE, datetime)
21 DATEADD(units, num, datetime) Add an interval to datetime DATEADD(units, num, datetime)
22 DATEDIFF(units, start, end) Get datetime difference in units DATEDIFF(units, start, end)
23 DATEFORMAT(datetime, format) Convert datetime to string CONVERT(VARCHAR(n), datetime, style)
24 DATENAME(datepart, date) Get the name of datepart as a string DATENAME(datepart, date)
25 DATEPART(datepart, date) Get datepart as an integer DATEPART(datepart, date)
26 DATETIME(exp) Convert exp to TIMESTAMP CONVERT(DATETIME, exp)
27 DAY(datetime) Extract day from datetime DAY(datetime)
28 DAYNAME(datetime) Get the name of the weekday DATENAME(DW, datetime)
29 DAYS(date) Get the number of days since Feb 29, 0000
DAYS(date, num) Add num days to date DATEADD(DAY, num, date)
30 DB_ID(database_name) Get the database ID number DB_ID(database_name)
31 DB_NAME(database_id) Get the name of a database DB_NAME(database_id)
32 DEGREES(num) Convert radians to degrees DEGREES(num)
33 DOW(date) Get the day of the week as integer DATEPART(DW, date)
34 ERRORMSG() Get the last error message STR(@@ERROR)
35 EXP(n) Raise e to the nth power EXP(n)
36 EXPRTYPE(exp, integer) Get the data type of exp User-defined function
37 FIRST(exp) Aggregate to return the first row only TOP 1 exp
38 FLOOR(num) Get the largest preceding integer FLOOR(num)
39 GET_BIT(bit_array, position) Get specified bit in a bit_array User-defined function
40 GETDATE() Get the current date and time GETDATE()
41 GREATER(exp, exp2) Get the greater of two expressions CASE expression
42 HASH(string[, algorithm]) Get the specified value in hashed form HASHBYTES(algorithm, string)
43 HEXTOINT(hexadecimal) Convert hexadecimal to integer CONVERT(INT, hexadecimal)
44 HOUR(datetime) Extract hour from datetime DATEPART(HH, datetime)
45 HTML_DECODE(string) Decode special HTML characters User-defined function
46 HTML_ENCODE(string) Encode special HTML characters (SELECT string FOR XML PATH(''))
47 HTTP_DECODE(string) URL decoding User-defined function
48 HTTP_ENCODE(string) URL encoding User-defined function
49 IDENTITY(exp) Get the sequential number of a row ROW_NUMBER()
OVER(ORDER BY (SELECT 1))
50 IFNULL(exp, exp2[, exp3]) Return exp2 if exp is NULL,
otherwise exp3
CASE expression
51 INTTOHEX(integer) Convert integer to hexadecimal CONVERT(VARBINARY(8), integer)
52 ISDATE(string) Check for a valid datetime ISDATE(string)
53 ISNULL(exp, exp2, …) Return first non-NULL expression ISNULL(exp, exp2)
COALESCE(exp, exp2, …)
54 ISNUMERIC(string) Check for a valid numeric ISNUMERIC(string)
55 LESSER(exp, exp2) Get the lesser of two expressions CASE expression
56 LOG(numeric) Get natural logarithm LOG(numeric)
57 LOG10(numeric) Get base 10 logarithm LOG10(numeric)
58 MINUTE(datetime) Extract minute from datetime DATEPART(MI, datetime)
59 MOD(dividend, divisor) Get remainder (dividend % divisor)
60 MONTH(date) Extract month from date MONTH(date)
61 MONTHNAME(date) Get the name of the month DATENAME(MONTH, date)
62 NEWID() Generate GUIDs NEWID()
63 NOW([*]) Get the current date and time GETDATE()
64 NULLIF(exp1, exp2) Return NULL if exp1 = exp2 NULLIF(exp1, exp2)
65 NUMBER([*]) Get the sequential number of a row ROW_NUMBER()
OVER(ORDER BY (SELECT 1))
66 PI([*]) Get number pi PI()
67 POWER(value, n) Raise value to the nth power POWER(value, n)
68 QUARTER(date) Get the quarter of the year DATEPART(Q, date)
69 RADIANS(numeric) Convert degrees to radians RADIANS(numeric)
70 RAND([integer]) Get random float value in (0, 1) RAND([integer])
71 REMAINDER(dividend, divisor) Get remainder (dividend % divisor)
72 ROUND(num, integer) Get rounded value ROUND(num, integer)
73 SECOND(datetime) Extract second from datetime DATEPART(SS, datetime)
74 SIGN(exp) Get sign of exp SIGN(exp)
75 SIN(num) Get sine SIN(num)
76 SOUNDEX(string) Get 4-character sound code SOUNDEX(string)
77 SQRT(num) Get square root SQRT(num)
78 SUSER_ID([user-name]) Get the server user’s ID SUSER_ID([user-name])
79 SUSER_NAME([user-id]) Get the server user’s name SUSER_NAME([user-id])
80 SWITCHOFFSET(tmz, offset) Change time zone offset SWITCHOFFSET(tmz, offset)
81 TAN(num) Get tangent TAN(num)
82 TEXTPTR(exp) Get pointer that conform to LOB TEXTPTR(exp)
83 TODATETIMEOFFSET(tms, tz) Convert to DATETIMEOFFSET TODATETIMEOFFSET(tms, tz)
84 TODAY([*]) Get the current date CAST(GETDATE() AS DATE)
85 TRUNCNUM(numeric, integer) Truncate numeric User-defined function
86 TRUNCATE(numeric, integer)
87 TSEQUAL(value1, value2) Compare two timestamp values value1 = value2
88 USER_ID([user_name]) Get user ID USER_ID([user_name])
89 USER_NAME([user_id]) Get user name USER_NAME([user_id])
90 XMLCONCAT(exp, exp2, …) Concatenate XML expressions
91 XMLELEMENT(NAME exp) Get an XQuery element node
92 XMLFOREST(exp, exp2, …) Get a forest of XML expressions
93 XMLGEN(construnctor, exp, …) Get XML based on constructor
94 YEAR(date) Extract year from date YEAR(date)

SELECT Statement

Converting SQL SELECT statement:

Sybase SQL Anywhere SQL Server
1 SELECT TOP n ... Select first n rows only SELECT TOP n ...
2 SELECT FIRST col, … Select the first row only SELECT TOP 1 col, …
SELECT FIRST(col) …
3 SELECT col,… INTO var, … FROM … Select a single row into variables SELECT @var = col, … FROM …
4 SELECT col,… INTO table FROM … Create and insert into table SELECT col,… INTO table FROM …

CREATE TABLE Statement

Converting CREATE TABLE statement from Sybase SQL Anywhere to SQL Server:

Sybase SQL Anywhere SQL Server
1 DEFAULT GLOBAL AUTOINCREMENT (partition_size) Autoincrement column IDENTITY
DEFAULT AUTOINCREMENT
2 Multiple AUTOINCREMENT columns allowed per table Only one identity
column per table is allowed
2 DEFAULT TIMESTAMP Auto-updated timestamp GETDATE() and trigger
3 col data_type COMPUTE (exp) Computed column col AS (exp)
4 INLINE num Data type attribute Removed
5 PREFIX num Data type attribute Removed

Foreign key actions:

Sybase SQL Anywhere Microsoft SQL Server
1 ON UPDATE RESTRICT NO ACTION
CASCADE CASCADE
SET NULL SET NULL
SET DEFAULT SET DEFAULT
2 ON DELETE RESTRICT NO ACTION
CASCADE CASCADE
SET NULL SET NULL
SET DEFAULT SET DEFAULT

CREATE FUNCTION Statement

Converting user-defined SQL functions from Sybase SQL Anywhere to SQL Server:

Sybase SQL Anywhere SQL Server
1 CREATE FUNCTION name CREATE FUNCTION name
2 IN param datatype(length) DEFAULT default @param [AS] datatype(length) = default
2 RETURNS datatype(length) RETURNS datatype(length)
3 [NOT] DETERMINISTIC Removed
4 ON EXCEPTION RESUME Continue execution in an error occurs Removed, it is the default behavior
5 [AS] [AS]

For more information, see Conversion of Procedural SQL Statements.

CREATE PROCEDURE Statement

Converting stored procedures from Sybase SQL Anywhere to SQL Server:

Sybase SQL Anywhere SQL Server
1 CREATE PROCEDURE name CREATE PROCEDURE name
2 IN | OUT | INOUT param datatype(length) DEFAULT default @param datatype(length) = default OUT
3 RESULT (col datatype(length), …) Result set definition Removed, not required
4 AS is optional AS required

For more information, see Conversion of Procedural SQL Statements.

CREATE TRIGGER Statement

Converting triggers from Sybase SQL Anywhere to SQL Server:

Sybase SQL Anywhere - Watcom-SQL SQL Server
1 CREATE TRIGGER name CREATE TRIGGER name
2 when event(s) ON table ON table when event(s)
3 BEFORE When to fire trigger Not supported, converted to INSTEAD OF
AFTER AFTER | FOR
INSTEAD OF INSTEAD OF
4 INSERT, UPDATE, DELETE Trigger events (list) INSERT, UPDATE, DELETE
5 REFERENCING OLD AS old NEW AS new inserted and deleted system tables
6 FOR EACH ROW Row-level trigger Cursor for inserted and deleted
7 No AS keyword before the trigger body AS keyword is required

For more information, see Conversion of Procedural SQL Statements.

Procedural SQL Statements

Converting Transact-SQL and Watcom-SQL statements:

Sybase SQL Anywhere SQL Server
1 DECLARE var datatype(length) Variable declaration DECLARE @var datatype(length)
2 DECLARE LOCAL TEMPORARY TABLE name (columns)
ON COMMIT DELETE | PRESERVE ROWS
DECLARE @name TABLE (columns)
3 DECLARE name EXCEPTION FOR SQLSTATE VALUE 'sqlstate' Declaration not required, removed
4 IF condition THEN … ELSEIF/ELSE … END IF IF statement IF condition BEGIN … END ELSE …
IF condition BEGIN … END ELSE …
5 SIGNAL exception_name Raise an exception RAISERROR('error text', 16, 1)

Cursors:

Sybase SQL Anywhere SQL Server
1 DECLARE cur CURSOR FOR select Cursor declaration DECLARE cur CURSOR FOR select
2 DECLARE cur INSENSITIVE CURSOR … No new rows appear DECLARE cur INSENSITIVE CURSOR …
3 DECLARE cur DYNAMIC SCROLL CURSOR … Can see new rows DECLARE cur CURSOR DYNAMIC SCROLL …
4 OPEN cur [WITH HOLD] Open cursor OPEN cur
5 FETCH cur INTO v1, … Fetch cursor FETCH [FROM] cur INTO v1, …
6 FETCH NEXT … Fetch next row FETCH NEXT FROM …
7 CLOSE cur Close cursor CLOSE cur
8 DEALLOCATE [CURSOR] cur Deallocate cursor DEALLOCATE cur

Cursor status:

Sybase SQL Anywhere SQL Server
1 @@SQLSTATUS = 0 Row found @@FETCH_STATUS = 0
@@SQLSTATUS = 2 Row not found @@FETCH_STATUS <> 0
2 SQLSTATE <> '02000' Row found @@FETCH_STATUS = 0
SQLSTATE = '02000' Row not found @@FETCH_STATUS <> 0

Executing stored procedures:

Sybase SQL Anywhere SQL Server
1 CALL sp_name (param1, ...) Executing a procedure EXEC sp_name param1, ...

UPDATE Statement

Converting UPDATE statement:

Sybase SQL Anywhere SQL Server
1 UPDATE tab [AS alias] SET alias.col ... Alias for table UPDATE tab SET col ... Alias cannot be specified