Skip to content

Tag: sql-server

SQL Query for multiple joined tables

I am querying against a SQL Server database and I’ve been struggling to get the result set I want. I feel like it is possible but I’m just unable to do it. Here is how the DB is layed out. I’d like to return a result set that looks like this: I’ve unsuccessfully tried using CTE’s…

Insert row with uniqueidentifier

This is a snippet from a stored proc that creates a database. We have a table with uniqueidentifier PK. I’m trying to insert a row with an empty guid as the PK: The error messages are Can’t see what’s wrong with the VALUES clause but I guess it has something to do with the final quote, altho…

Unable to replace the hour in datetime using SQL

Unable to replace the hour part in date-time. The change is reflecting in both hour & year. Please help in rectifying the code. Expected output = 2021-02-13 11:35:32.337 Actual output = 1121-02-13 11:39:11.347 Expected output = 2021-02-13 22:35:32.337 Actual output = 2221-02-13 22:38:13.223 Answer REPLACE…