I want to get the subscriber that has maximum value of Bill (Total Bill). I tried using the following script but SQL did not execute successflly. Please help me on what I did wrong on this. I have 2 tables: Subscriber FirstName MIN Ben 258999542 Reed 458524896 Steve 586692155 Clint 1007772121 Frank 1287548752…
Tag: sql-server
Concatenate or merge many columns values with a separator between and ignoring nulls – SQL Server 2016 or older
I want to simulate the CONCAT_WS SQL Server 2017+ function with SQL Server 2016 version or older in order to concatenate many columns which values are strings like that: Input: Output: Notice that the output result is a new column that concatenate all values separated by ‘|’. The default value sho…
Returning data from XML data in a column in a SQL Server database
Trying to extract data from a column in a SQL Server table. The column however is not of type XML but the data is in XML format (see below). I can extract the data I need via the CAST function, but looking to see if there’s a more efficient query to do so. The data below exists in the details
SQL Report Builder: Issue with SUM in VarChar Column
I’m back with what is probably a very simple question but (as a SQL newbie) I can’t seem to figure it out. I’m basically running a fairly simple report for a hospital. They want a report that details …
SQL If statement – check if row count of subquery = 1
Any suggestions on how to do this? I have a complex if statement in a query that needs to check on various conditions for a given table. EG: IF EXISTS (SELECT Labeler FROM [xx].[dbo].[manuf] …
LINQ double INNER JOIN on query translation when using selectMany
I have the following LINQ statement: Which uses the repository pattern. The search function is the one below: When I inspect the command that arrives in SQL Server I see that the query is translated in the following SQL: It works perfectly, but why there is an inner join duplicated: is a non-sense to me! If I…
SQL Query Inactive Users with last end date
This is a follow up from a question I asked about a year ago Old thread The answers I got then have worked fine but now I discovered that I need to tweak the query to be able to get the latest end …
Get pair-wise single row
I have some data in a MS SQL Server database. Sample data is: Sl ColumnA ColumnB 1 111 112 2 112 111 3 113 114 4 114 113 5 115 116 6 116 115 Now I need result like. ColumnA ColumnA 111 112 113 114 115 116 Notice here: In Sl 1 number Column A = Sl 2 Column B
How to Select one Value for each row after Joining of 2 Tables
I have 2 tables, the first one has 10 distinct values: , each GlobalPnID has many values on the second table, I want to join 2 tables and select one random value of PortionKey of the second table that match the condition and move to the next GlobalPnID Answer
Getting Error as @Parameter1 is not a parameter for procedure
I am learning mvc from this video where I am getting data from a form and saving it to database. When I ran my code first it gave an error stating Procedure or function ‘spAddEmployee’ expects parameter ‘@Employee_Name’, which was not supplied. I followed a solution in which I initiali…