How to get next value of SQL Server sequence in Entity Framework?

You can create a simple stored procedure in SQL Server that selects the next sequence value like this: CREATE PROCEDURE dbo.GetNextSequenceValue AS BEGIN SELECT NEXT VALUE FOR dbo.TestSequence; END and then you can import that stored procedure into your EDMX model in Entity Framework, and call that stored procedure and fetch the sequence value like … Read more

Last executed queries for a specific database

This works for me to find queries on any database in the instance. I’m sysadmin on the instance (check your privileges): SELECT deqs.last_execution_time AS [Time], dest.text AS [Query], dest.* FROM sys.dm_exec_query_stats AS deqs CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest WHERE dest.dbid = DB_ID(‘msdb’) ORDER BY deqs.last_execution_time DESC This is the same answer that Aaron Bertrand provided … Read more

Joining multiple tables returns NULL value

That is because null on either side of the addition operator will yield a result of null. You can use ISNULL(LiabilityPremium, 0) Example: ISNULL(l.LiabilityPremium,0) + ISNULL(h.LiabilityPremium,0) as LiabilityPremium or you can use COALESCE instead of ISNULL. COALESCE(l.LiabilityPremium,0) + COALESCE(h.LiabilityPremium,0) as LiabilityPremium Edit I am not sure if this is coincidence with this small data set … Read more

Why the SQL Server ignore the empty space at the end automatically?

SQL Server is following the ANSI/ISO standard for string comparison. The article How SQL Server Compares Strings with Trailing Spaces explains this in detail. SQL Server follows the ANSI/ISO SQL-92 specification… on how to compare strings with spaces. The ANSI standard requires padding for the character strings used in comparisons so that their lengths match … Read more