I want to get all Titles and Scores for a Given skill Id, every skill has titles mandatorily but there may not be records in the Answer table matching the condition A.[ServiceId] = 45 in this case i still need to display all the Titles and 0 as score For this purpose i made LEFT Join and still it doesn’…
Tag: sql-server
Procedure with cursor has missing output
I am working on an SQL Server procedure that I would like to have print the department name and students name Similar to the attached snippet The formatting should look like the attached sample snippet and there are two columns involved. students and department tables. The problem is that the results are inco…
Using SQL to group consecutive items that share a common status (dummy data included)
Given a table that has sometimes repeated statuses within a group (in this case “vehicles”), I want to consolidate those statuses into a single row and aggregate status_seconds. The data looks like this (I’ll include some TSQL below to select dummy data into a temp table to make it easy to w…
SQL Statement summarize missing employee certifications
I am trying to create a report on tables that I can’t modify and am not sure if this is even possible. Using the script below, I am trying to get a query result of: Answer You can cross join employees and certifications to generate all possible combinations, then use a subquery to check whether each tup…
Hide a row based on a condition in WHERE
My title might be confusing, so I’ll try to explain the best I can. I have two tables LEFT: table numbers RIGHT: table contracts: I want to show, for each instance where there’s a number associated …
How to do not null check on LEFT function on the select query
I have a query that returns some demographics like firstName, lastName, MiddleName and i need to use LEFT function on each to filter the First Letter of each column like LEFt(firstName, 1).This is …
SQL Server: log database changes through generic trigger
Starting from this article, which is creating a trigger to log insert-, update- and delete-statements within the database, I’d like to create a similar trigger which doesn’t require to define the table and its columns. This would us to reduce human errors when dropping or adding columns. I’v…
Order by with formatted dates, doing it right?
I wanted a mere sanity check because I have a slight feeling I am doing it all wrong. I stripped down the use case to a very simple sample. When formatting a date I need to cast the data in the order …
SELECT statement with where clause on Column
I am trying to gather some data from a table with INNER JOIN with another table. What I am trying to get have 2 Types and I need to separate these 2 types in 2 different columns. In table where I am Inner joining have a column called ‘Data’ and another Column called ‘Type’ depending on…
How to parameterize logins when executing SQL from PowerShell command
How do we run CREATE LOGIN … against a variable string? I’m executing the following command: MasterDBSetup.sql: How do we run CREATE LOGIN … against $(SvcRRRComparisonUser) ? Answer In the $SqlVariables: Then in the SQL file: