I am trying to create a SQL query that will pull the number of rows since the last maximum value within a windows function over the last 5 rows. In the example below it would return 2 for row 8. The …
Tag: sql-server
Deploying multiple SQL jobs in the same .sql file
So this is something I already do with Stored Procedures, and a bunch of other database items, and now I’m trying to do it with jobs. I write a bunch of items to a single .sql file. Other programs I …
Query to obtain the maximum primary key ID of a table for each unique value of the customerID column in the same table
I’m trying to run a query that takes obtains the maximum QuestionnaireId value for each unique value in column VendorId. So for example from this table: QuestionnaireId VendorId 1 …
Search for and reverse engineer foreign key relationships in DB without foreign keys defined
I’ve inherited a really old database with about 100 tables. I know there are foreign key relationships by looking through tables, but I’ve also determined that there are no relationships actually …
Large SQL table delete all duplicates
I have a database table with 33265902 (thirty-three million two hundred sixty-five thousand nine hundred two) records in it. Much of this is made up of duplicates. It is causing me issues as any …
How to Join 3 Tabels in Sqlserver
I tried to join 3 tables all together but when I execute the query only the first row on the table is displayed. The table consists of many rows. How can I display multiple rows? This is the code that I tried Member table enter image description here Books table enter image description here lend table enter image description here
Date format is not working in some computers, SQL Query
Below date format is not working in some computers I do know why, I use SQL Query. What is the problem? Please anyone can help me Answer I tried to convert variable instead of converting in SQL Query
How to apply datediff function in select statement using case statement
I have a stored procedure to select columns of tables like this whenever I am executing this query, it isn’t showing any error but it’s not calculating the the datediff in LapsedDay column in ms SQL. Any help related to this will be greatly appreciated. Answer = NULL is not correct. Comparisons to NULL almost always return NULL. Just simplify
Is there a way to write an insert statement with string_split which ignores duplicates?
I am trying to insert rows into a table using string_split command. It works fine if there are no duplicates. However, if there are duplicates, it errors out. I would like to know how to modify the …
How to separate values with Parse name in SQL Server
I have a value (500 , 850 , 65.5) as GivenUnitPrice and I want to separate these by making separate columns by PARSENAME I have tried like this and the result is Answer Seems you want to seperate the characters by commas but Parsename() function splits by dot character( e.g. decimal number 65.5 is also splitted as if seperate integers