[Solved] convert sql query into lambda expression [closed]

Query expression is much simpler in this case. I don’t recommend you to use lambdas with many joins from l in db.Listing join p in db.Place on l.PlaceId equals p.Id join pb in db.Place on p.ParentPlaceId equals pb.Id join a in db.Address on pb.AddressId equals a.Id where l.Id == 9 select new { UnitNumber = … Read more

[Solved] SQL Server Char/VarChar DateTime Error [closed]

This should look more like this: DateTime now = DateTime.Now; DateTime after1month = DateTime.Now.AddMonths(1); SqlCommand cmd = new SqlCommand(“SELECT * FROM TABLE WHERE THEDATE BETWEEN @now AND @after1month”, connection); cmd.Parameters.Add(new SqlParameter(“@now”, System.Data.SqlDbType.DateTime).Value = now); cmd.Parameters.Add(new SqlParameter(“@after1month”, System.Data.SqlDbType.DateTime).Value = after1month); Sometimes you can do it directly on SQL Server side using query: SELECT * FROM TABLE … Read more

[Solved] SQL, PHP update query

Use the mysql_affected_rows function to find the number of records affected. Please see following code. $record = mysql_query(“update table set a=”$b”, b=’$c’ where id = ‘$id’ “); $total_rows = mysql_affected_rows($conn); echo $total_rows; where $conn is the connection object 0 solved SQL, PHP update query

[Solved] Group by – Each Date summary value [closed]

You were close. You need to move the CASE…END inside the SUM() and drop TRS.DATE from the GROUP BY and ORDER BY. SELECT TRS.ITEM, SUM(CASE WHEN CAST(TRS.DATE AS DATE)=’2022-01-01′ THEN TRS.QTY END) D1Q, SUM(CASE WHEN CAST(TRS.DATE AS DATE)=’2022-01-02′ THEN TRS.QTY END) D2Q, SUM(CASE WHEN CAST(TRS.DATE AS DATE)=’2022-01-03′ THEN TRS.QTY END) D3Q, SUM(CASE WHEN CAST(TRS.DATE AS … Read more

[Solved] Using gridview to display string data vertically in a row

Assuming I understand your need, you could try something like the following: /* Create a mock-up table with sample data */ DECLARE @Data TABLE ( InstrumentID INT, InstrumentType VARCHAR(50), InstrumentNumber INT, NANumber INT, DateTimeFiled DATETIME, [Name] VARCHAR(255) ); INSERT INTO @Data ( InstrumentID, InstrumentType, InstrumentNumber, NANumber, DateTimeFiled, [Name] ) VALUES ( 1625168, ‘ACCOUNTS RECEIVABLE’, 1, … Read more

[Solved] SQL statement for getting top 5

If I understand correctly, you want the top 5 countries that appear the most times in the ads table, and for each one of those countries you want to display its most frequent section. The query below selects the top 5 countries by grouping the ads table by country and ordering the count and uses … Read more