Skip to content

Tag: sql-server

Change all bit columns to int with default value NULL

I have a database where we would store Yes/No questions as bits. However, as the project is going to a different path, we need to change all bit data types to int with default value NULL. Trying the following query, I get object is dependent of column error. To fix this I try doing: However, the fact that the…

DROP Constraint without knowing the name

I know there are a lot of references out there for what I am going to mention. I am rather sharing something I feel should be very useful and consolidating in one place – Q&A-style. I have struggled earlier finding this for different constraints on different time. The following constraints are commo…

Apply SUM( where date between date1 and date2)

My table is currently looking like this: I’m trying to sum values of ‘ON_Prepaid’ over the course of 7 days, let’s say from ‘2020-01-01’ to ‘2020-01-07’. Here is what I’ve tried Things should be fine if the dates are continuous; however, there are some mis…

SQL Check if the User has IN and Out

I need help getting the User which has an ‘IN’ and ‘Out’ in Column isIN. If the user has an IN and OUT do not select them in the list. I need to select the user who has only had an IN. Please I need help. Thanks in advance. This is the table: Need to get the result like I

Include Column name in SQL Unpivot

I have an unnormalized data set I need to normalize for reporting purposes. I successfully unpivoted the data using this: How can unpivot column headers Question1, Question2, Question3, Question4 as a third column in my unpivot query, like this? Answer Your syntax looks like SQL Server. If so, just use a APPL…