I am using SQL Server 2014. Below is the extract from a table called Table1: ID Market Adult AdultAge 0-5 6-12 13-17 100 UK 1 50 0 0 0 105 UK …
Tag: sql
Create a stored procedure which includes return records
I am trying to create a stored procedure which has 3 parameters. Another software will call my procedure with parameters in order to query a bunch of records. The stored procedure includes only a …
INSERT ‘X’ If another column is updated
I need to update column firstname in table Taulu ( removing single quotes ). I also need to add ‘X’ to another column sq if values where updated. I would like to update this in one statement. What I …
Adding SQL Rows from two CTEs
I have two CTEs that I’ve unioned two produce the following result: date serie events 2019-05-09 hello 175 2019-05-02 hello 196 2019-05-09 goodbye 1 2019-05-02 goodbye 1 I want to add …
why “CURRENT_TIMESTAMP” showing wrong time in SQL?
I am using “CURRENT_TIMESTAMP” for automatic date setup inside the column for each row in SQL. It shows date and time but time is wrong. please help.
Multiple batches in a SQL transaction
I want to create several stored procedures (or user-defined functions) within a transaction. CREATE PROCEDURE statement must be the only statement in the batch, so I have to use following template: …
How to add “or” in SQL select query?
I am creating a report to get customer wise incoming payment in a particular period. Payment can be received through Cheques, Direct Bank Transfers, Cash. This payments saved in the database in a …
how to rewrite query to put data-modifying CTE at top level
I’m trying to write a query for Postgres to insert a row into one table which as a side-effect may insert a row into a second table (due to the first table having a foreign key constraint on the …
Group By and Count the total number of same status value
I have 2 tables, Order and Store. And here are some of the fields from the table I need. Order table OrderId StoreId SystemOrderStatus 1 1 Received 2 1 Sent …
How to insert records to temptable which has ;with command in sql?
I have created a temp table which I want to fill with records. Here is my query: create table #temp(companysitetankid int, [SourceGradeName] varchar(50), SiteCode varchar(50)); ;with cst as ( …