All Questions
207
questions
2
votes
2
answers
66
views
Complex reporting query suggestion needed for different approach as per latest Tsql format
We have recently migrated from SQL Server 2008 R2 to SQL Server 2017 web edition. I am not a SQL developer but enthuses to learn.
Since many of our scrips are of old SQL format, I am searching for ...
4
votes
1
answer
193
views
Basic schemas for database and tables creation, bulk import from .csv and basic queries
The following SQL code serves the purpose of assessing basic SQL Server literacy.
I am creating database and tables schemas, inserting data from .csv files.
Constructing 8 simple queries as answers to ...
3
votes
2
answers
128
views
all appointment based on interval distance
Currently with a given Date and an Interval in Day, I can calculate all of the appointment in the future. for example if you are ...
5
votes
2
answers
760
views
Query with multiple foreign keys to the same table
I have a primary table, REP_ASSIST.ES_LOG with multiple columns that are foreign keys to another table, ...
4
votes
2
answers
188
views
Function to get current value or default from a string of two values
I have SQL scripts that I want to be executable directly in the editor (like DataGrip or SSMS) and also in automated integration tests. However, in each use-case they require different environment and ...
3
votes
1
answer
90
views
SQL Sub-query with running total optimization
The codes below get the rows of data until it reaches the total running quantity limit.
Notice that the SQL uses sub-query. ...
1
vote
1
answer
30
views
T-SQL Getting Sequential events with first even criteria
I have a query I am writing where I want output if a person has some service provided, then I want all the services they had provided after that and I don't want the individual returned if that is the ...
3
votes
1
answer
1k
views
Daily SQL job to delete records older than 24 hours
Below is a delete job to delete 1M+ records daily and takes 13 hours to complete and sometimes more than that. I need to optimize this.
The table tblcalldatastore is being inserted 24*7 through a ...
12
votes
1
answer
291
views
Safe dynamic SQL for generic search
Prompted by discussion about SQL injection, I wanted to put a proof of concept forward to get feedback about whether this is in fact safe and protected against SQL injection or other malicious use. ...
1
vote
2
answers
94
views
Combining two queries in one
What I want is getting all names (first, middle, last) of the users along with each of their total hours of work which will be calculated by the SQL statement: ...
1
vote
0
answers
90
views
Select splat in a subquery [closed]
Obviously, 'select *' is never a good idea.
HOWEVER, I have taken a job with an org that allowed this cancer to spread.
They have huge queries, using ...
1
vote
1
answer
95
views
T-SQL query Choose name of clients, concluded more than one loan agreement in 2010
QUESTION: Choose the name of clients,
concluded more than one loan agreement in 2010,
as the numbers and dates of issue of these contracts.
Sort by name of the client and date of issue of the loan.
...
3
votes
1
answer
43
views
T-SQL Query remove duplicates except for original row from the table
Question:
There is an Exam_Merge table into which to import
records from a similarly structured table in another database.
In this case, the Exam_Merge table contains the values of the primary key ID
...
4
votes
1
answer
235
views
SQL query to count loans issued during each week
Calculate the number of loans issued by the Regional offices for each business week in the period from 38 to 40 business week of 2011 inclusive. Sort by name of the regional unit, business week.
...
4
votes
1
answer
1k
views
SQL e-commerce database design
I want as an exercise to create an e-commerce application from bottom up. My main goal here is to gain a lot of knowledge. I have experience in web development, but never have been there from the ...