[Solved] I need a sql query to view data

SELECT cities.cityname, states.statename, countryname FROM cities JOIN states ON cities.states_id = states.id JOIN country ON states.country_id = country.id WHERE cities.id=3; Assuming 3 is the id of the city you are searching for… solved I need a sql query to view data

[Solved] Sql Data Summery [closed]

use a recursive cte that starts with elements whose frompoint matches no topoint in a self join so as to identify the starting points. then eleminate the intermediate results by joining again and use only those data whose topoint match no frompoint in another self join. with cte as ( select r.name, r.frompoint, r.topoint from … Read more

[Solved] An Update statement in a loop

This can be done with a single update statement. delete from question where id = 2; with new_order as ( select row_number() over (partition by survey_id order by question_no) as new_question_no, question_no as old_question_no, id from question ) update question set question_no = nq.new_question_no from new_order nq where nq.id = question.id and survey_id = 44; … Read more

[Solved] getting previous data (one less running column)

Try this Query:- SELECT CMPI_PRCINX AS CURRENT_PRICE, (SELECT MAX(CMPI_PRCINX) FROM CMD_MTRL_PRICE_INF WHERE CMPI_PRCINX<(SELECT MAX(CMPI_PRCINX) FROM CMD_MTRL_PRICE_INF)) AS PRIVIOUS_PRICE FROM CMD_MTRL_PRICE_INF WHERE CMPI_PRCINX = (SELECT MAX(CMPI_PRCINX) FROM CMD_MTRL_PRICE_INF GROUP BY CMI_CODE) here is the SQL Fiddle Code. http://sqlfiddle.com/#!4/46a23/2 solved getting previous data (one less running column)

[Solved] Optimize query using Concat method

I would try with this : SELECT [CaseID], STUFF( (SELECT CONCAT(‘; ‘, A.[AssignedPathologist]) FROM CTE1 A WHERE A.[CaseID] = B.[CaseID] FOR XML PATH(”) ),1, 1, ” ) As [AssignedPathologist] FROM (SELECT DISTINCT CaseID CTE1 B) B; For newer versions you can use string_agg() : SELECT CASEID, STRING_AGG(AssignedPathologist, ‘; ‘) AS AssignedPathologist FROM CTE1 C1 GROUP … Read more

[Solved] Whats wrong with my SQL?

Your last query SELECT 0, department, department_name, ”, ‘NP’ as acc_code, ‘NET PROFIT/(LOSS)’ as acc_name,1, SUM((CASE WHEN acc_code=”CS” OR acc_code=”EX” THEN -1*yr_balance ELSE yr_balance END)), SUM((CASE WHEN acc_code=”CS” OR acc_code=”EX” THEN -1*ly_balance ELSE ly_balance END)), SUM((CASE WHEN acc_code=”CS” OR acc_code=”EX” THEN -1*mn_balance ELSE mn_balance END)), SUM((CASE WHEN acc_code=”CS” OR acc_code=”EX” THEN -1*lm_balance ELSE lm_balance END)), … Read more

[Solved] Convert nvarchar(255) to date SQL

You can take advantage of SQL Server’s flexibility to recognize various date formats. If you have the right regional settings, this should just work: cast(mycol as date) This gives you back a value of date datetype that corresponds to the input string; Demo on DB Fiddle: select cast(‘Jan 18 2019 12:00AM’ as date) | (No … Read more

[Solved] How subquery works?

The query in the parenthesis is called a correlated sub-query. That is because, if you look at the first FROM, it has an alias for the salary table FROM salary a, which in this case is a. The sub-query references the outer query in the WHERE b.salary > a.salary condition, where it checks the condition … Read more