sql-server-2017

SQL Convert Milliseconds to Days, Hours, Minutes

泪湿孤枕 提交于 2019-12-04 06:08:51
I need convert a millisecond value, 85605304.3587 to a value like 0d 18h 21m. No idea on how to start that, is there something similar to a TimeSpan in SQL like there is in C#? You can do the calculation explicitly. I think it is: select floor(msvalue / (1000 * 60 * 60 * 24)) as days, floor(msvalue / (1000 * 60 * 60)) % 24 as hours, floor(msvalue / (1000 * 60)) % 60 as minutes Note: Some databases use mod instead of % . In MS SQL SERVER you can use next code: with cte as ( select cast(85605304.3587 as int) / 1000 / 60 as [min] ), cte2 as ( select cast([min] % 60 as varchar(max)) as minutes,

STRING_AGG not behaving as expected

好久不见. 提交于 2019-12-03 10:44:57
I have the following query: WITH cteCountryLanguageMapping AS ( SELECT * FROM ( VALUES ('Spain', 'English'), ('Spain', 'Spanish'), ('Sweden', 'English'), ('Switzerland', 'English'), ('Switzerland', 'French'), ('Switzerland', 'German'), ('Switzerland', 'Italian') ) x ([Country], [Language]) ) SELECT [Country], CASE COUNT([Language]) WHEN 1 THEN MAX([Language]) WHEN 2 THEN STRING_AGG([Language], ' and ') ELSE STRING_AGG([Language], ', ') END AS [Languages], COUNT([Language]) AS [LanguageCount] FROM cteCountryLanguageMapping GROUP BY [Country] I was expecting the value inside Languages column for

Parameterization(Always Encrypted)- Inside stored proc

橙三吉。 提交于 2019-12-02 00:42:22
I have a scenario where i need to have literals(hard coded strings) inside proc used against "Always Encrypted" columns, Since this fails with the following error, Operand type clash: varchar is incompatible with nvarchar(20) encrypted with (encryption_type = 'DETERMINISTIC', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'CEK_Auto4', column_encryption_key_database_name = 'DBName') I am trying to do Parameterization for Always Encrypted within the stored proc, similar to below GO CREATE PROCEDURE InsertProc @Var1 nVarchar(20) As BEGIN DECLARE

Get unique values using STRING_AGG in SQL Server

久未见 提交于 2019-12-01 16:39:43
问题 The following query returns the results shown below: SELECT ProjectID, newID.value FROM [dbo].[Data] WITH(NOLOCK) CROSS APPLY STRING_SPLIT([bID],';') AS newID WHERE newID.value IN ('O95833', 'Q96NY7-2') Results: ProjectID value --------------------- 2 Q96NY7-2 2 O95833 2 O95833 2 Q96NY7-2 2 O95833 2 Q96NY7-2 4 Q96NY7-2 4 Q96NY7-2 Using the newly added STRING_AGG function (in SQL Server 2017) as it is shown in the following query I am able to get the result-set below. SELECT ProjectID, STRING

SQL Server 2014 installation stuck (hung up) or taking very long time to finish

情到浓时终转凉″ 提交于 2019-11-30 19:20:12
I'm trying to install SQL Server 2014 but it stays in the same spot (Install_VCRuntime_Cpu32_Action) for hours. It's already the third time I'm trying to install so I don't know what else to do. SQL Server 2014 Installation Update[19/June/18] : Today one of my colleagues faced this very same issue with SQL Server 2017 setup installer as well. I observed this very same issue in one of my colleague's windows 10 box with SQL Server 2014 Enterprise installer as well. As mentioned in this MS connect bug you can try either of the below mentioned options: As mentioned by KevinMS in comments tab : I

CLR Strict Security on SQL Server 2017

拜拜、爱过 提交于 2019-11-30 06:46:49
MSDN on this article says: CLR uses Code Access Security (CAS) in the .NET Framework, which is no longer supported as a security boundary. A CLR assembly created with PERMISSION_SET = SAFE may be able to access external system resources, call unmanaged code, and acquire sysadmin privileges. Beginning with SQL Server 2017, an sp_configure option called clr strict security is introduced to enhance the security of CLR assemblies. clr strict security is enabled by default, and treats SAFE and EXTERNAL_ACCESS assemblies as if they were marked UNSAFE. The clr strict security option can be disabled

Produce DISTINCT values in STRING_AGG

独自空忆成欢 提交于 2019-11-29 13:46:10
I'm using the STRING_AGG function in SQL Server 2017. I'd like to create the same effect as COUNT(DISTINCT <column>) . I tried STRING_AGG(DISTINCT <column>,',') but that is not legal syntax. I'd like to know if there is a T-SQL work-around. Here is my sample: WITH Sitings AS ( SELECT * FROM (VALUES (1, 'Florida', 'Orlando', 'bird'), (2, 'Florida', 'Orlando', 'dog'), (3, 'Arizona', 'Phoenix', 'bird'), (4, 'Arizona', 'Phoenix', 'dog'), (5, 'Arizona', 'Phoenix', 'bird'), (6, 'Arizona', 'Phoenix', 'bird'), (7, 'Arizona', 'Phoenix', 'bird'), (8, 'Arizona', 'Flagstaff', 'dog') ) F (ID, State, City,

CLR Strict Security on SQL Server 2017

混江龙づ霸主 提交于 2019-11-29 06:51:11
问题 MSDN on this article says: CLR uses Code Access Security (CAS) in the .NET Framework, which is no longer supported as a security boundary. A CLR assembly created with PERMISSION_SET = SAFE may be able to access external system resources, call unmanaged code, and acquire sysadmin privileges. Beginning with SQL Server 2017, an sp_configure option called clr strict security is introduced to enhance the security of CLR assemblies. clr strict security is enabled by default, and treats SAFE and

Produce DISTINCT values in STRING_AGG

狂风中的少年 提交于 2019-11-28 07:19:52
问题 I'm using the STRING_AGG function in SQL Server 2017. I'd like to create the same effect as COUNT(DISTINCT <column>) . I tried STRING_AGG(DISTINCT <column>,',') but that is not legal syntax. I'd like to know if there is a T-SQL work-around. Here is my sample: WITH Sitings AS ( SELECT * FROM (VALUES (1, 'Florida', 'Orlando', 'bird'), (2, 'Florida', 'Orlando', 'dog'), (3, 'Arizona', 'Phoenix', 'bird'), (4, 'Arizona', 'Phoenix', 'dog'), (5, 'Arizona', 'Phoenix', 'bird'), (6, 'Arizona', 'Phoenix'