Skip to content

SQL -Listing between Two dates for each record

My data source looks like below. And I want output like below. Basically, it should list each Employee multiple times for each date between those periods. For quick and easy, below is the Temp Data code. Answer Build a calendar table and join that.

Get values “0” and “1” alternated rows on SQL

I’m using SQL Server 2015, I have a table with a list of values “name”, my necessity is to add a column that alternate values “0” and “1” when the “name” columns changes. This is important for me because, I import this query on excel, and I will format the…

How to declare a cursor inside another cursor

How declare another cursor inside cursor c_employees? Note: cursor c_employees return employees_id and this id pass to other cursor in the where clause. For example Answer Cursors can take parameters hence But generally, when you start seeing cursors with cursors etc etc…its also time to look at whether…

postgres syntax error on grant select on table

I have a query: But on running this: I get the following syntax error: without grant query its working fine. What am I missing here? Answer To specify the schema, use ON public.abc. The syntax IN SCHEMA public can only be used with ON ALL TABLES. Also, you have to separate CREATE TABLE and GRANT with a semico…

Return records of one value and not in other values

Apologies for asking such simple question but here I am getting trouble while getting records from single table, my table contains records which have different values in prod_code for similar product_number. I want records of such product_number which have specific prod_code, and not others. For example from …

MYSQL: Can’t update table in stored function/trigger

I have a table called “report” I am trying to create a trigger for in case insert a state with value “failed” for the ip_element “10.66.16.55” and path “/dev/map/4-4”, the state change to “ok” I get the next error: Answer You cannot update the table …