[Solved] Need help to UPDATE TABLE [closed]

you are saying that on change in four table you want to update the record in 5th table. For this purpose you can write an update trigger which will trigger on change on any one of the four tables and check if the needed values in four tables are updated and it will change accordingly … Read more

[Solved] Relationship between tables in ms sql server [closed]

your table structure should be below PatientTable PatientId int Primary Key, PatientName varchar(50), EmailId varchar(50) Password varchar(50) TestTable TestId int Primary key, TestName varchar(50) PatientTestTable PatientId int FK(PatientTable) TestId int FK (TestTable) This way you can give relationship to two tables. you need to understand funamental of RDBMS. 1 solved Relationship between tables in ms … Read more

[Solved] Sql Query Between Different Databases like Oracle and SQL Server in C# [closed]

You will need to install the Oracle Client first. Google “Oracle Database Client windows” to find the download from Oracle’s site. 1) Install the 64-bit package first. (VERY important as there is a bug that messes things up if you install the x86 package first) 2) Change the install path to “C:\oracle\x64” 3) Once installed … Read more

[Solved] T-SQL | SQL-Server Pivot [closed]

Try: select Agent, max(case when `desc` = ‘Total’ then ColValue else 0 end) Total, max(case when `desc` = ‘Replaced’ then ColValue else 0 end) Replaced from tbl group by Agent Demo sqlfiddle 1 solved T-SQL | SQL-Server Pivot [closed]

[Solved] SQL Server : how to sum? [closed]

SELECT SUM(Value) FROM TableName; Using a GROUP BY (per your comment above) is when you want things grouped over a subset. In this case, a group by would return the same info you’ve sampled, because there’s no groups to sum on the desc field… however if you had two “e” descriptions (let’s say 40 for … Read more

[Solved] Convert month and year columns to a date column with additional string concatination

Assuming your are using date and MSSQL2012+: SELECT UPPER( FORMAT(CONVERT(datetime, ‘2017-02-01′,121),’MMM’)) + ‘-‘ +RIGHT(CAST( YEAR( CONVERT(datetime, ‘2017-02-01’,121)) AS VARCHAR(4)),2) M_DELIVERY , ‘DELIVERY FOR ‘ +UPPER( FORMAT(CONVERT(datetime, ‘2017-02-01′,121),’MMM’))+’ ‘+ CAST( YEAR( CONVERT(datetime, ‘2017-02-01’,121)) AS VARCHAR(4)) AS Description Other way(using numbers and not date): (you can change months name abbrev.) SELECT SUBSTRING(‘GENFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC’,1+(MONTH_NUMB-1)*3,3)+’-‘+ RIGHT(YEAR_NUMB,2) AS M_DELIVERY , ‘DELIVERY … Read more

[Solved] Subquery returned more than 1 value. wrong if statement [closed]

You do not need any of these IF..ELSE statements or even the sub-queries in your select, what you are after, can be achieved with the following simple select query: CREATE PROC GET_ORDER_ACCOUNT_DETAILS @ORDERID INT AS BEGIN SET NOCOUNT ON; SELECT CASE WHEN od.calcType=”K” THEN od.price * od.kilo ELSE od.quant * od.price END as [AMOUNT] ,od.quant … Read more

[Solved] What is the difference between OUTER APPLY and OUTER JOIN, and when to use each? [closed]

First, I do not really know which is the default OUTER JOIN in T-SQL (I’d bet FULL), but in any case, I think it is unclear – it is best to use LEFT, RIGHT, OR FULL JOIN explicitly when you need one. JOIN joins tables. Already existent ones or subqueries. APPLY applies (duh) a table-valued … Read more

[Solved] How do display top 5 products from specific category [closed]

First, let’s define what we need. We need a table (view) with these fields: ProductId, ProductName, ProductViewCount, and RootCategoryId. Imagine, the Category table has RootCategoryId field already. Then we can use this query to receive the result: SELECT P.Id AS ‘ProductId’, P.Name AS ‘ProductName’, PVC.ProductViewCount, C.RootCategoryId FROM Category C INNER JOIN ProductCategory PC ON PC.CategoryId … Read more