I’m trying to run an alter user command as sa in SQL Server: However when I do so I get this error: Msg 15151, Level 16, State 1, Line 1 Cannot alter the user ‘MyAppDemoAdmin2’, because it does not exist or you do not have permission. I see that the user does exist in the user list, so I mus…
Tag: sql
Can Foreign Key on a table be three different tables as primary keys (each table primary key data is different)?
I have a reminder table (ParentId) – Foreign key to ProductId from Product and also OrderId from Order table. Is it possible? When I try to insert the data for the Reminder table belongs to OrderId, I’m getting Foreign-Key constraint error. Answer You can do this with a bit of work, using foreign …
Conditional Query Using “AS” field
Above you can see my code. It is currently returning exactly the output I want when you remove the “WHERE” function. I’m adding the “WHERE” function and attempting to access the new column I made called “NPO”. It seems as if the column does not exist to the SQL editor…
How do I generate random number with a range X times in SQL SERVER
I want to generate a random number X times with a range. I’ve tried to create a function: CREATE FUNCTION Random_Number (@Times INT, @Upper BIGINT,@Lower BIGINT, @randomvalue numeric(18,10)) RETURNS …
How can I determined which users with a specific RoleID that’s not been active within a time interval? And which home department do they belong to?
This script below will tell me how many non active users with a certain RoleID there’s been within a timeframe. When I run the script below. It will also tell me which home department each user …
SQL Lag() to Find Datetime Difference
I am trying to find the difference between Datetime entries in my sql table and was following this article – https://blog.jooq.org/2015/05/12/use-this-neat-window-function-trick-to-calculate-time-…
Find pair of customers(CustID), who have bought same number of items.(SQL Nested Query)
Invoice (InvoiceNo, CustID, OutletID, Date) PK(InvoiceNO) InvoiceItems (InvoiceNo, ItemID, Quantity, Discount) PK(InvoiceNO,ItemID) PLz tell me solution of Above mention Query using nested Method …
The INSERT statement conflicted with the FOREIGN KEY constraint in Entity framework core, 2 tables in single statement
I have following 2 classes. public partial class Query { public int Id { get; set; } public virtual QueryGroup QueryGroup { get; set; } } public partial class QueryGroup { public int Id {…
How to do an UPDATE with several SELECT in value to update in MSSQL
I’m trying to update a value which is the result of 2 SELECT UPDATE table2 SET value = (SELECT value FROM table1 WHERE table1.id = (SELECT value2 FROM table3 WHERE table3 = Value3 )), …
SQL – Aggregates data with dates interval
i’m facing a problem joining two table with date interval that represent user status change. ID is the same in both table. Table_A ID StatusA FromA ToA 1 Active 01/01/2020 10:…