How to set the user rights by passing the database name as Input parameter in a stored procedure? Declare @username nvarchar(100) Declare @databasename nvarchar(100) set @username = ‘ABC’ CREATE …
Tag: sql
Disable trigger in another db(Oracle)
Can I create a procedure that disables a trigger in another database? I mean, can I disable it with a database link? I need it for importing data into a data warehouse
Single Item Order – AdventureWorks
I am wondering if my answer works for this problem? The answer I was able to find on the internet seems similar but they join another table which seems ambiguous. Question: A “Single Item Order” is …
Convert/get varchar variable to YYYYMM
I have 4 CTE’s in this table and the third one contains a DATETIME converted to VARCHAR (with format based on the requirement) as startDate in DD/MM/YYYY format. The last cte does calculations based …
Select values with a more recent year and month when both are stored in different columns in SQL Server
The setup in both tables is that year and month are in two seperate columns as numbers. I am trying to select the values from one table that do not exists in the other table (so are more recent date wise). For example: Table1 has values from 2016 until today and Table2 only until end of 2018. So I want
Easy table transpose in hive
I need to transpose my table. Now i have that type of table: But i want to get the next result How should i transpose my table for achieving this result? Answer Use case statements with min() or max() aggregation:
SELECT COUNT with JOIN optimization for tables with > 100M rows
I have following query SELECT SUBSTRING(a0_.created_date FROM 1 FOR 10) AS sclr_0, COUNT(1) AS sclr_1 FROM applications a0_ INNER JOIN package_codes p1_ ON a0_.id = p1_.application_id …
Why we need a primary key?
I am reading about primary keys and at a lot of tutorials, technical blogs etc., and I found that a primary key cannot be null. I think it’s totally wrong because I was able to insert null value in the column. I suppose a primary key can have a not null value only if the column is declared as not
WordPress: How to update data in database using PHP with MySQL?
I am using core PHP to make WordPress custom page template for my website, but when I am updating user id, it was not updating the user id. Suppose I have a user in database and when the user pay amount using PayPal, make that user id 1. By default its id is 0. I want to make that user
If null in one table select from Other
I have 2 tables inquiry and Application table I want to build a view that contains the user information based on data from these two tables. Example I Have Table Inquiry FirstName, LastName, Address, email I have table Application FirstName, LastName, Address, email Am querying the tables using the email fiel…