I want to display different dates as columns from LOGDATE column. Here are the details My query: This query returns this result: Expected output format: I have multiple types of SERVICE_TYPE and SERVICE_NAME, not just the three sown in the sample. How can I get my expected output? Any help would be appreciate…
Tag: sql-server
How to use a list/array of values as column name in select statement?
Say I have 3 list of data that I am using to build a new query. I need to take these list of data and return the values of those list where things were found. So my question is this: Is there a standard method of taking a list and using it as a column? I will need to use
Datediff on 2 rows of a table with a condition
My data looks like the following Now, I want to calculate the datediff between the closeddates for teams A, and B, if the max closeddate for team A is greater than max closeddate team B. If it is smaller or null I don’t want to see them. So, for example,I want to see only one record like this : and
Using Group By as part of a where clause
I’m trying to eliminate certain records from a dataset using SQL Server. The title of my post may be inaccurate, as a better solution may exist than what I have in mind. In my query, I am selecting …
sql – Get the Minimum Value of 2 subqueries
I have a query which has 5 subqueries. I need it to have only 4 subqueries, since two of them are supposed to be only one result. The problem is I don’t know how to maintain the query structure and …
How to Fix Error Msg 41337, Level 16, State 100 in Create Memory Optimize table in SQL Server
I want to use a memory optimize table and I got below error – how can I fix it? Any idea will be helpful. Msg 41337, Level 16, State 100, Line 1 Cannot create memory optimized tables. To create memory optimized tables, the database must have a MEMORY_OPTIMIZED_FILEGROUP that is online and has at least o…
SQL compare the incremental difference from a column
Let’s say I have a table with the columns CurrentDateTime and CurrentValue where the CurrentValue column mostly increments. Sometimes though, the CurrentValue resets, this is where the issues start. …
Flagging amount thresholds reached per user
Story: Two conditions: I need to calculate the amount of days it takes a user to spend over 20, 50 and 100$ based on his register_date If someone’s first purchase is > 100$ then the amount of days …
How can i get a zero in front of the week number when it is a one-digit number?
I want to get the week number, and I did using DATEPAR(WEEK,DATE) , however, one-digit week numbers do not come with a zero in front. Basically I need to get 01, 02, 03 instead of 1, 2, 3.
T-SQL – Count unique characters in a variable
Goal: To count # of distinct characters in a variable the fastest way possible. DECLARE @String1 NVARCHAR(4000) = N’1A^’ ; –> output = 3 DECLARE @String2 NVARCHAR(4000) = N’11’ ; –> output = …