I’m trying to create a string from table values, along with some text to make it more readable. The only problem I’m having is that I can’t get the SELECT statement to work inside my CONCAT. It’s been bugging me for quite some time now, and I would appreciate any feedback on what IR…
Tag: sql-server
Xquery Get Consecutive Distinct Values
Trying to get consecutive distinct from the following XML. Expected Result : Current Result : Code : The distinct-values get distinct from the whole set, but I would like to get distinct values only if there are consecutive. Answer We have a pure XQuery solution. SQL Output
String or binary data of ” would be truncated
I’m trying to resize a column down to 64 characters in length: but I get the following error: String or binary data would be truncated in table ‘dbo.consumption’, column ‘resourceGroup’. Truncated value: ”. This doesn’t make sense to me: how can you truncate nothing? …
Concatenate 2 rows into one in SQL
I have a very simple data structure with just 3 tables: requests employees teams Basically, what I need is to concatenate 2 different SQL selects into one (so that the query could return just one row). If there’s an employee associated with a request, then return their name (title) and concatenate it wi…
How to get output parameter and also a table when executing a stored procedure
Scenario I’m working with SQL Server 2017 (not possible to change) I’m using Visual Studio 2019 in C# console and .NET Framework 4.5 (possible to change) I’m using ADO.NET because several years before we couldn’t use Entity Framework, as the system is made to work with a stored procedu…
SQL query based on column condition
I have a sql table in which below are the columns. I’m using sql server. Id, name, device and information on if device is active or not. Need to have a SQL query for below scenario: I want to display firstdevice, seconddevice columns below based on isActive column. If isACTIVE is 1 then, fill the device…
Trying to extract data form SQL using PS script
I have been trying to get a PS script to work in extracting files (pdf, word, etc.) from an SQL Server database. I came across the PowerShell script below. The script runs and populates the destination folder but all files are 0 bytes and during the script execution. It throws the error: “Exporting Obje…
SQL Statement with the same multiple subqueries running very slow
I am hoping someone here can help me. I have been given this query that takes a long time to run (over 30 min). I have been trying to rewrite the query but with no luck thus far. I am posting an example of the query so that you can get an idea of what it is I am trying
Using SSIS OR T-SQL Split a column of quoted & unquoted comma separated values into multiple columns
I have comma separated data in a column named C0. The data in C0 looks like this: C0 “Pacey LLC.”,213830ZZ,11/1/2017,11/1/2017,”297,311.74″,”2,371.40″,0.00,”1,325.18″,0.00,42.22,”123,986.56″ Mike The Miker,9814140VCD,12/1/2018,12/1/2018,”3,917,…
Is it better to pivot data in SQL or in my application code?
I have a very long & narrow table in a MSSQL Database, one that looks a bit like: date dataItemName dataItemValue 2021-01-01 Units Sold 20 2021-01-01 # Customers 2948 2021-01-01 ARP 19 2021-01-02 Units Sold 146 2021-01-02 # Customers 157 2021-01-02 ARP 32 And I’m trying to get a table of the form: d…