[Solved] Multiple if Result = [closed]

Perhaps what you’re looking for is an Array or List. Both of these can contain a sequence of multiple values, which would allow you to do this, for example: var resultArray = new[] { sqlCmd2.ExecuteScalar().ToString(), sqlCmd3.ExecuteScalar().ToString() }; // Read results with resultArray[0], resultArray[1] Another option is to assign each result to an object property: var … Read more

[Solved] SQL query for formatted output [closed]

I assumed Time column Value are fixed and that are 1,3,5,7. Below Query is similar to what you wanted to achieve. select distinct T.id,T.iMid, (select amount from myTable where time = 1 and id = T.id and iMid = T.iMid) as Time1, (select amount from myTable where time = 3 and id = T.id and … Read more

[Solved] SQL function PIVOT with 2 column

select order_number, line_number, isnull(max(case when linenum=1 then name else null end),”) name1 , isnull(max(case when linenum=1 then value else null end),”) value1, isnull(max(case when linenum=2 then name else null end),”) name2, isnull(max(case when linenum=2 then value else null end),”) value2, isnull(max(case when linenum=3 then name else null end),”) name3, isnull(max(case when linenum=3 then value else … Read more

[Solved] Delete all rows except the one with the biggest value

DELETE FROM `transactions` WHERE id NOT IN ( SELECT MAX(id) FROM `transactions` group by user_id ) The inner query groups by each user and select only the highest ID for each. Delete all records except the IDs from the inner select. 0 solved Delete all rows except the one with the biggest value

[Solved] extract sub string from string in oracle

Use a regular expression to replace everything from each ~ tilde character until the next comma , or pipe | character (exclusive of that final character): Oracle Setup: CREATE TABLE your_data ( input_string ) AS SELECT ‘(,QUESTION-3914~Please enter the unique identification number associated with the IRQ.|3~Greater Than|5~5,AND,QUESTION-3920~Select the contract action that applies to this IRQ.|5~Equal … Read more

[Solved] SQL Server Transpose Rows Into New Table

I figured it out. See below for the code. INSERT INTO Results (eventID,Result1,Result2,Result3,Result4,Result5) SELECT eventID, [1] as Result1, [2] as Result2, [3] as Result3, [4] as Result4, [5] as Result5 FROM (SELECT [inputTable].eventID,[inputTable].eQualType,[inputTable].Value1 FROM eventQData WHERE eQualType IN (1, 2, 3, 4, 5) AND (Value2 > 0) ) AS inputTable PIVOT (MAX(Value1) FOR [eQualType] IN … Read more

[Solved] SQL — SELECT 3 TABLES WITH 2 IDs

This is a very bad data model. Change it if you can. If there is a column gender in the client table, why muddle through with some generic list? Just add a table gender and link to its rows with client.gender_id: table gender (gender_id, description) table client (client_id, name, gender_id) If you really must make … Read more

[Solved] Convert a string to date in SQL Server

I guess you want something like this DECLARE @str VARCHAR(50)= ‘1 year 12 months 2 days’ DECLARE @days INT= LEFT(@str, Charindex(‘ ‘, @str)), @months INT = Substring(@str, Charindex(‘months’, @str) – 3, 2), @years INT = Substring(@str, Charindex(‘days’, @str) – 3, 2); WITH days_back AS (SELECT Dateadd(day, -@days, Cast(Getdate() AS DATE)) AS day_date), month_back AS (SELECT … Read more

[Solved] Count SQL Query [closed]

Either of these will work. The second is better, but the first will show you how you can go about this when grouping by isn’t so straight-forward (or achievable). SELECT ISNULL(SUM(CASE WHEN OS_NAME = ‘Linux’ THEN 1 ELSE 0 END), 0) AS [Linux Servers], ISNULL(SUM(CASE WHEN OS_NAME = ‘Windows’ THEN 1 ELSE 0 END), 0) … Read more