How to fetch latest entry done in a table for every minute, for every parameter

I have records in tables saved like this: ID | PID | Param | Param Value | Date time | —|——-|——–|————-|———————— 1 | 195 |Param 1 | 12 |2015-11-25 17:41:05.000 2 | 211 |Param 2 | 13 |2015-11-25 17:41:05.000 3 | 195 |Param 1 | 14 |2015-11-25 17:41:35.000 4 | 211 |Param 2 | 15 […]

SQL Server with Cross Join Unpivot

I have a unique cross apply. I have a table that looks like this. ID What I would like to see to see is if this can be split into 2 rows and 4 columns. I would like to split the SUB together and the APP together. ClaimID === SUB Cost === APP Cost === […]

Automatic cache sizing for sequences in SQL Server 2012

I was trying to create a sequence in SQL Server 2012 using below T-SQL script: Create Sequence ConteoCycling AS int START WITH 2 MINVALUE 0 MaxVALUE 4 INCREMENT BY 1 GO I gave it a min (0) and max (4) range values so that it recycles itself once the given range is consumed. After successful […]

TSQL get COUNT of rows that are missing from right table

There was one other SIMILAR answer but it is 2 pages long and my requirement doesn’t need that. I have 2 tables, tableA and a tableB, and I need to find the COUNTS of rows that are present in tableA but are not present in tableB OR if update_on in tableB is not today’s date. […]

Minimum and maximum memory usage in SQL Server?

I’ve been looking around but my google-fu isn’t too good these days it seems. I’m trying to find more information about the minimum and maximum memory settings for SQL Server instances. If you open SQL Server Management Studio, right-click on an instance, and go to the ‘Memory’ tab in the left-hand menu, you can find […]

Purge job optimization

SQL Server 2008 R2 Enterprise I have a database with 3 tables that I am keeping a retention time of 15 days. This is a logging database that is very active and about 500 GB in size and eats about 30GB a day unless purged. I can’t seem to get caught up on one of […]

Primary key in table

I have table USERLIST with [UserName],[AppId] and data will be like UserName AppId ——– —– abc 1 abc 18 abc 2 abc 24 abc 29 abc 30 abc 33 abc 4 abc 5 abc 6 abc 8 xyz 1 xyz 18 xyz 2 My query will be mostly on USERNAME like select applist.APPID ,applist.APPDESC ,applist.APPTHUMB […]

CREATE FUNCTION failed because T-SQL and CLR types for return value do not match

I have created a .Net assembly that returns a set of records. When I create a function in SQL Server, I get the message CREATE FUNCTION for …failed because T-SQL and CLR types for return value do not match. I am a bit lost, does anyone have a clue what is going wrong? This is […]

ROW_NUMBER is not working in CTE

I was playing around reports and it appeared that row_number is not working in recursion. !! I have simplified the example!! From table with 3 records: declare @sometable table (id int, id2 int) insert into @sometable select 1 as id, 11 as id2 union all select 2, 22 union all select 3, 33 In CTE […]

How to compare the columns of two tables, SQL Server?

I understand creating a join and comparing the values of specific columns from two tables. In this case, I am only interested in comparing the columns between two different tables, not the values. I want to check to see if I have the correct number of columns in my new table, and that the spelling […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.