I want to create a trigger which will check if my showtime with Cinema Hall Id exist or not. This will prevent me from booking one Cinema hall at two same Showtimes. Secondly in this trigger I am also checking if the showtime I am assigning to movie lies in movie release and last date range or not. But I
Tag: tsql
How to select only one row if a value of a column occurse multiple times in the result?
I have a table like this on: AttributeA AttributeB AttributeC AttributeD A B EQUALITY D 123 B EQUALITY D 456 B C D … … … … My goal is, to create a Select-Query where the result only contains one row with an equal AttributeC – no matter of the count of rows with the same value in this column.
SQL replace and insert Into
I have this table “NamesTable” in SQL Server. I want to insert and replace in a second column the corresponding name like this This is my query: The query runs and replace the selected words, but do not insert into my existing table. What I am doing wrong? Answer No idea what is the objective of your INSERT query. But
How to Further Group Items in a Column After Group By
I have an SQL table named “DATA” as follows: I’m attempting to return the following 3 columns: plan, planCount, totalCostPerPlan I’ve been working a query to return this and so far it looks like this: It sort of works, however, I get the data only partially grouped as follows: (The table is just an example) How to I further group
SQL Server CASE expression that does not result in waterfall
If I have a case expression is there a way it does not work as a waterfall? For example if I have the following dataset: Is there a way I can show the following results To show Right now it shows as Answer You can use a left join instead:
SQL query returns 0 for COUNT(*) if no rows
I just got started with SQL and joined this forum recently, thus I’m still lacking the knowledge. Please do be considerate if I’ve made any mistakes. I intend to get the data from the past n days. For each day, the query will count the total rows and return the result. However, there are no records for some of the
Joining tables based on datetime2 predicate
How do I join tables A and B (see pic) on TripID and where TimeTriggered is between SegmentStart and SegmentEnd? I could try: However since BETWEEN is inclusive on both ends it would join alarm B to both segment 1 and 2. I could try >= AND < but it would leave out alarm C. I could try > AND
What is mean name after variable name in t-sql
I have the next query: Сan you please explain what it means instruction: Is a variable called startdate assigned a different name? But why? Answer First, I would write this as: The two are equivalent, but this is clearer in intent (and less likely to cause problems). In any case, @startdate is not a valid column name in a table
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 column
Insert query: Column name or number of supplied values does not match table definition
This is a table that auto increments the ID, takes the time input, and sets the default of the total column as zero and the date column with getdate() So the only value that I have to insert is the time. However on insertion SQL Server gives me this error: Column name or number of supplied values does not match