Skip to content
Advertisement

Tag: tsql

How to select a foreign key after narrowing down via Group By and Having in a subquery

I’ve got a unique problem. I’m querying a replicated database table cost_plan_breakdown, and the replication is known to have some duplicates due to issues with deleting records. I’m not the Admin so I’m trying to sidestep these duplicates as efficiently as possible. The table looks like this: sys_id sys_created_on cost_plan breakdown_start_date axr123 2020-10-01 09:31:15 Outlook KTLO – Lisa Lymon 10-01-2020

Apply SUM( where date between date1 and date2)

My table is currently looking like this: I’m trying to sum values of ‘ON_Prepaid’ over the course of 7 days, let’s say from ‘2020-01-01’ to ‘2020-01-07’. Here is what I’ve tried Things should be fine if the dates are continuous; however, there are some missing days in ‘Pre_Date’ (you know banks don’t work on Sundays, etc.). So I’m trying to

SQL Check if the User has IN and Out

I need help getting the User which has an ‘IN’ and ‘Out’ in Column isIN. If the user has an IN and OUT do not select them in the list. I need to select the user who has only had an IN. Please I need help. Thanks in advance. This is the table: Need to get the result like I

Query on how to replace numerical data from a string/column

I have values in my column as below. Can anyone help me with how to replace any numeric data present in a column or string to blank using SQL Server query? Below is the column data. How do I replace the numbers to blank and display only underscores. Answer You could approach this by counting the number of underscores, and

Stored Procedure not working with variables

I have a stored procedure as follows: When I run the above by passing the search variable as 04029125070527 I get no results. But if I edit my stored procedure as follows, I get a result. The only difference is in the above I’m trying to send the variable and in the second its hard coded (not what I want

SQL Update Multiple columns with counts

We currently have SQL update statements that works for our needs and updates the tbl_rprt table. Below are some of the update queries, there are several others like them. I was wondering if there was another way to get this done, maybe combining all of them into one SQL statement. #tbl_rprt is a report of all the counts of specific

Display total where row number is max row_number

I have a query that displays invoice information, and in final column displays the Supplier’s total balance, I only want the total to be displayed on the last line of that supplier’s invoice entries. ie. the results may contain 100 invoices for say 20 suppliers, each supplier having a different number of invoices, the Account_Total should only be displayed on

Highest Mark in each course with student name

I want to get the highest mark in each course with the title of that course and student name who toke that course exam. and i have these tables , first one students id name 1 Jhon Doe 2 Sarah Doe and Courses table id title 1 Math 2 history and i made a table for connecting students with courses

Updating SQL Variable

I’m attempting to create a variable that will hold a value, which I will then later use to select from a table using the variable value. This works perfectly the first time around, but any time I try and change the parameters to update the variable it returns blank. Am I able to use the same variable with different parameters?

Advertisement