[Solved] Convert this sql command to c# linq

var query = ( from v in dbContext.UnitFeatureValue join u in dbContext.Unit on v.FK_Unit_ID equals u.ID join t in dbContext.FeatureTitle on v.FK_FeatureTitle_ID equals t.ID where v.FK_Unit_ID == 15 && t.canMoreSelect == 1 select new { v.FK_Unit_ID, u.unitNumber, u.unitTitle, t.featureTitleName, }).Distinct(); 3 solved Convert this sql command to c# linq

[Solved] Convert this sql command to c# linq

Introduction This article will provide a step-by-step guide on how to convert a SQL command to a C# LINQ query. LINQ (Language Integrated Query) is a powerful query language that allows developers to write queries in a more concise and expressive way. It is a great way to simplify complex SQL queries and make them … Read more

[Solved] SQL Server – not displaying NULL values

Move the CA_AN subquery to a Cross Apply and check the is not null on the where clause SELECT REGION = et_region, [STORE CODE] = e.et_etablissement, [STORE NAME] = et_libelle, CA = CONVERT(DECIMAL(15,2),SUM(gl_totalttcdev)), NBRTICKETS = CONVERT(DECIMAL(15,0),COUNT(distinct(GL_NUMERO))), NBRARTICLES = CONVERT(DECIMAL(15,0),SUM(GL_QTEFACT)), UPT = CONVERT(DECIMAL(15,2),SUM(GL_QTEFACT)/COUNT(DISTINCT(GL_NUMERO))) , PM = CONVERT(DECIMAL(15,2),SUM(gl_totalttcdev)/COUNT(DISTINCT(GL_NUMERO))), CA_AN = MAX(CA_AN.caan) FROM piece LEFT JOIN ligne ON … Read more

[Solved] IF COL_LENGTH(‘EMP_NUM’,’EMPLOYEE’) IS NOT NULL – EQUIVALENT IN ORACLE [closed]

In Oracle, you have to use dynamic SQL as you can’t execute DDL in PL/SQL as is. Why PL/SQL? Because IF-THEN-ELSE is PL/SQL, not SQL. Presuming this is part of your PL/SQL procedure, you’d then if col_length(‘EMP_NUM’, ‘EMPLOYEE’) is not null then execute immediate ‘alter table employee modify emp_num not null’; end if; That’s for … Read more

[Solved] SQL query to get the multiple “,” positions from a string

Please try this one it will give output as yours. Create table #Table (rowNo int identity(1,1), ID varchar(100)) insert into #Table values(‘32132’) insert into #Table values(‘32132,32132’) insert into #Table values(‘32132,32132,6456,654,645’) declare @TableRow int = (select count(*) from #Table),@Tableloop int = 1 while(@Tableloop <= @TableRow) begin Declare @var varchar(100) ; SET @var = (select ID from … Read more

[Solved] SQL Field Length

You need just this: SELECT @list = seg_tag + ’01’ + RIGHT(‘0′ + CAST(LEN(ID_Type) AS varchar), 2) + ID_Type + ’02’ + RIGHT(‘0′ + CAST(LEN(IDNumber) AS varchar), 2) + IDNumber FROM #TEMP_TABLE_ID Or SELECT @list = seg_tag + ’01’ + CASE WHEN LEN(ID_Type) < 10 THEN ‘0’ ELSE ” END + + CAST(LEN(ID_Type) AS varchar) … Read more

[Solved] Order by two columns with usage of CASE WHEN

CASE is an expression that returns a single expression/value. You need to write one CASE statement per column: ORDER BY CASE WHEN @cOrderBy = ‘USER_FNM_USER_LNM ASC’ THEN USER_LNM END ASC, CASE WHEN @cOrderBy = ‘USER_FNM_USER_LNM DESC’ THEN USER_LNM END DESC, CASE WHEN @cOrderBy IS NULL THEN USER_KEY END ASC, CASE WHEN @cOrderBy = ‘USER_FNM_USER_LNM ASC’ … Read more

[Solved] SQL Server 2008 : calculate date and price change

Something like: DECLARE @artSales TABLE (artid int, dt date, price money); INSERT @artSales VALUES (1, ‘20170102’, 10), (1, ‘20170108’, 10), (1, ‘20170112’, 8.50), (1, ‘20170115’, 8.50), (2, ‘20170102’, 20), (2, ‘20170109’, 20), (2, ‘20170112’, 35), (2, ‘20170116’, 40), (3, ‘20170101’, 500), (3, ‘20170111’, 500), (3, ‘20170130’, 500); SELECT artid, dt, oldPrice = price, PriceChange = … Read more