Skip to content

Tag: sql-server

How to write an optional condition in SQL Join

I have two tables. One is the Transaction table and the other is the PriceBook table. I want to select the price from the PriceBook table, matching with the ItemID, Assortment and UnitID with Transaction table. But the UnitID match is optional, so if there is no match with UnitID, I want to have the matching …

Update column by removing text in braces

I need to update single column for all the rows in a table. The update should happen in such way that data needs be filtered out by removing all text where braces are appended for the string and swap the strings separated by ‘,’. Example: As per the above example, I need the final data to be somet…

Sql where Condition execution not working

I have the following query logic Show comments which is not deleted Show comments which is deleted after created, within a timespan of 30 days before today(Today – Createddate <= 30) Below is the logic which I wrote, but I don’t think it is working correct. Answer

How add select in list without join

I don’t need to join in a whole table, but just want a value from the table returned in my select list (but other tables are joined for other items). It’s giving me an error…incorrect syntax near select I’m having trouble searching online for this. Answer Assuming the scalar subquery r…