Skip to content
Advertisement

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: I’ve also unsuccessfully tried

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, although the final quote

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(@p, SUBSTRING(@p, 12, 2), ’11’) will replace all occurrences of SUBSTRING(@p, 12, 2) in @p by

Are inner parenthesis needed in the WHERE clause? or anywhere

In the WHERE section or anywhere really where you have multiple conditions like OR’s I know outer parenthesis are required but are the inner ones? For example my assumption is that Is the same as writing However if we remove the outer parenthesis then I know the query will be different. Example: And Are both the same thing but not

Advertisement