Convert SQL Server uniqueidentifier to MongoDB bindata uuid - sql-server

We can convert MongoDB bindata uuid to SQL Server uniqueidentifier by this query:
select cast(0x14e52693004d004caf19c169251a497c as uniqueidentifier)
outputs
9326E514-4D00-4C00-AF19-C169251A497C
convert mongodb bindata uuid to sql server uniqueidentifier
Can we convert SQL Server uniqueidentifier to MongoDB bindata uuid?

Related

SSIS SQL Server to Excel

I am trying to use SSIS to export a BigInt data type from SQL Server 2016 to Excel 2016 (.xlsx).
I'm having trouble with mapping the BigInt column to Excel. What is the data type to use for Excel?
Thanks

Decrypt data in SQL Server 2014 encrypted by SQL Server 2017 using EncryptByPassPhrase

I am trying to synchronize data between two databases(SQL Server 2014 and SQL Server 2017). The Windows application saves the data to SQL Server 2017 database using the encryptbypassphrase function. This encrypted binary data is transferred to SQL Server 2014 database. I am unable to decrypt the data using the decryptbypassphrase function in SQL Server 2014 database.
Below are scripts to replicate the issue.
In SQL Server 2017
declare #clearText nvarchar(max) = 'Hello world!'
select ENCRYPTBYPASSPHRASE('Password', #clearText)
prints 0x02000000DA28E89D43CC03C11BBDC34041B20BC3627D93CC84E73A83545F379316C0F016DB8A9E22CAABFACC9C70C956217E9604FB69B465C6FF251E397779F1EAEF2464
and
declare #encryptedValue varbinary(max)= 0x02000000DA28E89D43CC03C11BBDC34041B20BC3627D93CC84E73A83545F379316C0F016DB8A9E22CAABFACC9C70C956217E9604FB69B465C6FF251E397779F1EAEF2464
select Convert(nvarchar,DECRYPTBYPASSPHRASE('Password',#encryptedValue))
prints 'Hello world!'
In SQL Server 2014:
declare #clearText nvarchar(max) = 'Hello world!'
select ENCRYPTBYPASSPHRASE('Password', #clearText)
prints 0x010000008DE2368BEE3A899341956117C504F5DC1696A4847D6CFC0A276B2C2D1EFE0052045784B9DC1A9A1E552F4E927794AB0F
declare #encryptedValue varbinary(max)= 0x010000008DE2368BEE3A899341956117C504F5DC1696A4847D6CFC0A276B2C2D1EFE0052045784B9DC1A9A1E552F4E927794AB0F
select Convert(nvarchar,DECRYPTBYPASSPHRASE('Password',#encryptedValue))
prints 'Hello world!'
What I am trying to do is transferring the binary data from SQL Server 2017 to SQL Server 2014 and trying to decrypt the binary data
In SQL Server 2014
declare #encryptedValue varbinary(max)= 0x02000000DA28E89D43CC03C11BBDC34041B20BC3627D93CC84E73A83545F379316C0F016DB8A9E22CAABFACC9C70C956217E9604FB69B465C6FF251E397779F1EAEF2464
select Convert(nvarchar,DECRYPTBYPASSPHRASE('Password',#encryptedValue))
prints NULL
I expect the output to be 'Hello World!'

Copy arabic data from old SQL server database

I have existing data in SQL Server 2008 that has Arabic data in varchar column that I need to copy to SQL Server 2014. When I query the data I see text like èíë¢ïëë¢é Is there a solution. Can I do it through C# application.
I have tried INSERT using Arabic Collation on the source, bcp utility to export using codepage 1256.

SQL Server equivalent of Oracle NVARCHAR2(X)

Is the SQL Server datatype NVARCHAR(510) the equivalent of the Oracle datatype NVARCHAR2(255) (doubling because nvarchar2 in oracle) ?

Using SQL Server bcp to migrate data from datetime to datetimeoffset

I have two tables with almost the same structure, one in SQL Server 2005 and the other in SQL Server 2016. The only difference is that column ModifiedDate is of type datetime in SQL 2005 and datetimeoffset in SQL 2016.
I used bcp to export the data from SQL 2005 in native format to a file. Then I tried to use bcp to import the data file to SQL 2016. I got error:
[ODBC Driver 11 for SQL Server] Invalid field size for datatype
If I removed ModifiedDate column, export/import would run without any errors.
Does anybody know how to solve the problem?
When you export with BCP, instead of doing an OUT export directly for a table, do a QUERYOUT export with a query that converts the DATETIME field to a field with a format that is convertible to DATETIMEOFFSET.

Resources