Last post Feb 16, 2016 07:09 AM by TechView
Feb 15, 2016 08:41 AM|Yanayaya|LINK
I have a sql query that I need to translate into Linq. Normally this wouldn't be too much of a problem but there are a couple of items in this statement which I'm not sure how to generate in linq. The statement is as follows:
SELECT vessel_idx, vessel_name, spotlist_dp, spotlist_bhp, spotlist_deck, spotlist_bp, spotlist_oilrec,
spotlist_fifi, spotlist_rov, '' AS fixture_charterer, '' AS fixture_work,
CONCAT(fixture_charterer ,' ', mid(fixture_start,9,2),'/',mid(fixture_start,6,2)) AS next_charterer_info
, '' AS fixture_location,'0000-00-00 00:00:00' AS fixture_stop
, '' AS fixture_note
AND current_location_spotlist_id = 2
AND fixture_start > '2016-02-12 08:30:00'
AND vessel_status = 'PPT'
ORDER BY fixture_stop
The problems are specifically the selecting the column as a name with an empty value and the concatination. Please help.
Feb 16, 2016 06:25 AM|Zhi Lv - MSFT|LINK
You could try to use the following code:
FROM tb in tbl_vessels
WHERE tb.vessel_type =='AHTS'
&& tb.current_location_spotlist_id == 2
&& tb.fixture_start > '2016-02-12 08:30:00'
&& tb.vessel_status == 'PPT'
vessel_idx = tb.vessel_idx,
vessel_name = tb.vessel_name,
spotlist_dp = tb.spotlist_dp,
spotlist_bhp = tb.spotlist_bhp,
spotlist_deck = tb.spotlist_deck,
spotlist_bp = tb.spotlist_bp,
spotlist_oilrec = tb.spotlist_oilrec,
spotlist_fifi = tb.spotlist_fifi,
spotlist_rov = tb.spotlist_rov,
fixture_charterer = "",
fixture_work = "",
next_charterer_info = tb,fixture_charterer + " " + tb.fixture_start.Substring(9,2) + "/"+ tb.fixture_start.Substring(6,2),
fixture_location = "",
fixture_stop = "0000-00-00 00:00:00",
fixture_note = ""
Here are some relevant articles you could refer to them:
Feb 16, 2016 07:09 AM|TechView|LINK
SELECT Name AS Product, CONCAT(Price,' ', mid(Details,10,2)) AS Info FROM Products WHERE CategoryID = 2 ORDER BY ID;
var result = (from c in db.Products
where c.CategoryID == 2
order by c.ID
Product = c.Name,
Info = " " + c.Price + c.Details.Substring(10,2)