[Solved] SQL Server Converting Rows to Columns

You can get the output you desire with grouping and some CASE statements inside SUM aggregate functions: SELECT dbo.TableB.TrackingID, dbo.TableA.ParcelCode, dbo.TableC.CustID, SUM(CASE WHEN dbo.TableB.FinanceType=”Invoice” THEN dbo.TableA.TotalAmount ELSE 0 END) AS TotalAmount, SUM(CASE WHEN dbo.TableB.FinanceType=”Invoice” AND TransType=”Card” THEN dbo.TableA.TotalAmount ELSE 0 END) AS CardInvoice, SUM(CASE WHEN dbo.TableB.FinanceType=”Invoice” AND TransType=”Cash” THEN dbo.TableA.TotalAmount ELSE 0 END) AS CashInvoice, … Read more

[Solved] Exception DATABASE1.MDF’ cannot be opened because it is version 655. This server supports version 612 and earlier. A downgrade path is not supported

Exception DATABASE1.MDF’ cannot be opened because it is version 655. This server supports version 612 and earlier. A downgrade path is not supported solved Exception DATABASE1.MDF’ cannot be opened because it is version 655. This server supports version 612 and earlier. A downgrade path is not supported

[Solved] Mysql query – how to do this? [closed]

Try – SELECT id, SUM( DISTINCT ss ) AS “Sum (ss)” FROM tblData GROUP BY id; Note : Without GROUP BY SUM() will try to add up all values of ss, even with the DISTINCT qualifier. If you use GROUP BY but not DISTINCT then SUM() will add up all the values of ss for … Read more

[Solved] SQL and Counting

Give this a try: select name, count(case when grade in (‘A’, ‘B’, ‘C’) then 1 end) totalPass, count(case when grade=”A” then 1 end) totalA, count(case when grade=”B” then 1 end) totalB, count(case when grade=”C” then 1 end) totalC from t group by name Here is the fiddle. Or we can make it even simpler if … Read more

[Solved] SQL – Distinct with Case When

select distinct OENT.OTHER_EXTERNAL_ID AS AGENT_NUMBER, CASE WHEN SE.Organization_Name IS NULL OR RTRIM(LTRIM(SE.ORGANIZATION_NAME)) = ” THEN ” ELSE upper( SE.ORGANIZATION_NAME ) END AS AGENT FROM SomeTableName order by AGENT_NUMBER It will still return duplicates in case if Agent number differs. If you want to find duplicated names then select AGENT, count (AGENT_NUMBER) from ( select OENT.OTHER_EXTERNAL_ID … Read more

[Solved] Procedure in SQL Server query

You better specify all columns after your table #tempbe_budget like following: INSERT INTO #tempbe_budget( budgetno, Finyear, Deptid, ….. ) Add collation adjustment to your JOINS: FROM budget bud LEFT OUTER JOIN womaster wo ON wo.bcno1516 COLLATE SQL_Latin1_General_CP1_CI_AS = bud.newno COLLATE SQL_Latin1_General_CP1_CI_AS LEFT OUTER JOIN department dept ON dept.deptid COLLATE SQL_Latin1_General_CP1_CI_AS = bud.deptid COLLATE SQL_Latin1_General_CP1_CI_AS LEFT … Read more

[Solved] sql search in multi columns [closed]

Put parens around your or-ed conditions, and change the double quotes to single quotes for the year (as suggested by jarlh): select from products WHERE year=”2016″ and ( name like ‘%”& name &”%’ or size like ‘%”& Size &”%’ ) Oh and in case this is VB.NET and you got name and Size from a … Read more

[Solved] Select the newest data in an SQL table? [closed]

first, please dont use ‘date’ as your field name, lets say you rename it as news_date. How about this? <?php $query = mysql_query (“SELECT * FROM yourtable ORDER BY id DESC LIMIT 3”); $number = 1; while ($result = mysql_fetch_array($query)) { $id = $result[‘id’]; $title = $result[‘title’]; $news_date = $result[‘news_date’]; $post = $result[‘post’]; ?> <div … Read more

[Solved] MYSQL : Inner Join On Three tables

Try this:- Select a.roll_no, name, sport_name from student a inner join student_details b on a.roll_no=b.roll_no inner join sports c on b.sport_id=c.sport_id where a.roll_no in (1,3); ‘Where’ condition here helps restrict out to just Sandeep and Ajay. If you want for all then remove ‘Where’ condition completely 1 solved MYSQL : Inner Join On Three tables