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:
See also Sybase Adaptive Server Enterprise to SQL Server Migration.
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... |
Converting SQL and T/SQL language elements:
Converting numeric data types:
Converting other data types:
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) |
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 … |
Converting CREATE TABLE statement from Sybase SQL Anywhere to SQL Server:
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 |
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.
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.
Converting triggers from Sybase SQL Anywhere to SQL Server:
For more information, see Conversion of 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:
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, ... |
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 |