I have a dataset that looks like this: GO CREATE TABLE [dbo].[taskDB]( [ticket] [varchar](50) NULL, [created] [date] NULL, [closed] [date] NULL, [rating] [varchar](50) NULL [user] […
Tag: sql-server
Multiplying 2 column values in Dynamic SQL
This is giving the error message: Conversion failed when converting the varchar value ‘27.72081’ to data type int. Answer You’re casting numeric values to VARCHAR inside your dynamic statement. Remove the CASTs and it should be good. Your resulting statement should read something like this w…
How do I get the lates tm.detail_notes ( tm.detail_notes for max(tm.timeslip_date))?
I have a query that return some record, but I need to get whatever the latest tm.detail_notes on max(tm.timeslip_date). Right now I am getting an error. (I have multiple record dates on the table and each day have note) Query Error The text, next, and image data types cannot be compared or sorted, except when…
How can I add a row to my SQL results between each “category” change in the data?
I use SQL Server 2019 to produce a long list of shipping options. This list is produced by a simple query on a table containing the list items, and displayed on a handheld terminal. Users find it cumbersome and time-consuming to navigate the list to find the correct option, and must do so several times per da…
Are SQL Server unique constraints “Silent” or do they raise an exception?
I want to prevent inserting duplicate values into my tables. At first, I added code to check if the value already existed in the database, but that seems like a lot of overhead / wasted time if I can prevent it at the DDL level. So I found this and changed one of my tables (as an example) from this:
Is there a way to dynamically execute queries in SQL without using user defined function?
I am currently working on the table containing some documents data, focusing on the columns containing date of document and net income. What I have to do is to write an sql statement which will result …
SQL – Pick first row satisfying a condition below every row satisfying another condition
Suppose I have this table, named Table I want this result: That is: If Col1 = A and Col2 = 1, take the corresponding row If Col1 = A and Col2 = 0, take the first row below it where Col2 = 1 I tried something like but it’s not quite what I was looking for. I couldn’t come up
How to get row count based on other column groups
I need to count the number of dates with which the invoices are made to certain customers in each month Consider the table named Table1 I tried the folllowing code and the result was The result I need should count the column named branch based on column month, the desired result is Here rowcount is based on b…
How to split one column with array merge value to array and join other table then merge back
There’s a table WaitCheckBil like : and a table Users like : Expected result : What I’ve tried & think : It’s a old system’s table , so I can’t change the struct. And the table logic is select * from WaitCheckBil where usrs like ‘%;’ + @usr + ‘;%’; to …
Use a calculated column value to look up a specific value from the same source table
I have a table in SQL Server called ShippingDocSummary which contains all historical records for shipping documents. For a given document number, there can be any number of historical records/…