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
Tag: sql-server
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 …
Split text into multiline chunks based on fixed character length using SQL
I am looking for SQL that takes a string of text (coming in as up to 3 lines, but usually 1) and breaks it into at most 3 lines with a max of 30 characters per line. (The background is I’m trying to insert text into address line fields and sometimes the incoming values are longer than 30 characters and
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…
How to limit STUFF function within CTE for removing character before recurring word
A follow up question for Replace a recurring word and the character before it Credit to @Larnu for the following code, how would this code be modified to not produce a null value if there is no longer a character before a recurring word, “[BACKSPACE]”. I believe the null value is occurring because…
SQL Join using a Junction Table not returning expected results
I’m joining 3 tables in SQL Server for the purpose of mapping users to their managers. The purpose of the junction table is to map their full usernames to their network ID. Here’s the query: The first 3 columns appear as I’d expect, showing the Network ID, Full User Name and the Manager̵…
SQL Server 2019: Cannot combine two queries, when 1 parses string
There are two tables (table1 and table2). Table 2 has a column called TaskDescription which has a string with several ‘tags’ embedded in it. I cannot change how that data is stored, as it comes from a a third party. I am able to pull out the taskID I want to grab all of the information from table …
How can I conditional join two tables to get results based on an evaluation (SQL Server)?
I have two tables in my database: Offices Positions How can I select all entries from Positions based on their Department and Section, but one above their level? I’m guessing I need a join with some kind of condition that gets evaluated to do this. For example, the Senior Dev position is at level 1. So,…
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…