I have a subroutine that runs on a local copy of a database and a network stored master. To allow users to run my Excel add-in offline, I create a local version that has the same table names as the …
Tag: sql
Update a column using another column in the same table with two entries (Values) in SQL Server
I’m trying to update a column Product_Group from a column called Product in the same table. This Product column has two entries, Simple or Others. i.e shown below in Invoice table: The issue I’m have is that if you look at Top_Level ID 10, 19, 21 and 31 has multiple entries and the Product are mul…
Grant on dynamic database name in Postgresql
I am trying to grant a new user permissions on the current database (whose name I do not know). Basically I want to archive something like this: Any hints how this could be achieved? Answer You cannot combine GRANTs with queries directly, but you may write a small block to achieve that. Since GRANT allows onl…
Cannot insert the value NULL into column ‘ExampleID’
Upon executing I keep receiving the error: Cannot insert the value NULL into column ‘ExampleID’, table ‘DB_Example.dbo.tbl_Example’; column does not allow nulls. INSERT fails. However I don’t think any NULL values are present. I am trying to simply fill a table with specific valu…
How to calculate the a third column based on the values of two previous columns?
My sample data is as follows: Table T1: +——+——-+ | Item | Order | +——+——-+ | A | 30 | | B | 3 | | C | 15 | | A | 10 | | B | 2 | | C | 15 | +—–…
How to add a column in MSSQL with default value?
In MSSQL 2014 I would like to use an update syntax which is adding a new column with a default value. Is this possible somehow? Answer Here is a complete reproducible example. Create table Check contents Add new column with default value Check the result Here is a SQL fiddle with this example.
Apply if only on one column on result
This are sample template UserDetails : id,UserName,IsShow Brand : id,BrandName Product : id,ProductName BrandProduct:id,brandid,productid,price If Isshow is false, show entire price else …
PostgreSQL conditional ENUM
Let’s say I have a table inventory with columns item_id, category and size. item_id is auto incremented integer (primary key) category is ENUM size is ENUM I want size to be a conditional ENUM. …
Assigning multiple rows to a single row of different table SQL
Is it possible to assign several rows to a single row of a different table? Doing purchase order I have a table for Suppliers then under that I have items that are in the different table. Giving me …
Send mail every N days in SQL
I need to send a warning mail 14 days before certificates valid_to date ends and also send email every 3 days from delay_days. Table Certificates consists of: ID(int) | cert_valid_to(date) | …