Skip to content

Tag: sql-server

How create table with name which name in another table

There is a table in which all the names of the tables are located and I need to create a table with a name from it. I give id to the input of the stored procedure and by this number I need to pull the name from another table result some I need create database schema3.Users. And this table must

Sql Performance join Vs co-related Subquery

TABLE : employee (id,mid,join_date) Question – Find all employees who joined before their managers Query 1: Query 2: Which of them is correct? If both correct, then how is the performance? Answer They are both correct. Performance questions need to be tested on your data on your system. However, with a …

SQL with non-existing column in where cause can be executed

Here’s my SQL The issue is, the colA1 does not exist in TableB. So if I just run this Then SQL Server Management Studio will return an error: Invalid column name ‘colA1’. But if it is in the where cause, the first SQL can be executed as if where cause is always true. Answer Thats because SQL…

Email address lookup in SQL Server

We have a large subscriber database and have a lookup based on email address of type nvarchar(100). It sometimes times out probably because of a large scan of it. I want to improve this, but weary of some of the options. Would an index on it be ok, I can handle the additional storage if needed, or a computed …

Get row Sums across multiple users/tables

I am working in SQL Server, and I have three tables that I have simplified below USERS: POINTS: CLAIMS: I’m trying to run a report of distinct users with a sum of points earned and a sum of points used. I’ve started with the join of tables by userId… but of course that returns the user multi…