Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Convert to Lambda

Author  Topic 

Steve2106
Posting Yak Master

183 Posts

Posted - 2014-11-12 : 06:54:20
Hi There,

This is more than likely the wrong forum but there are some incredibly helpful people on here and this is normaly where I come when I have a problem.
I need to convert an Sql Query into a Lambda expression and was wondering if anyone could help me with it. This is the Sql Query:

declare @portid int
select @portid = PORTSID from tbPortActions
where PortID =
(select PortID from tbPortActions where PORTSID = 5843) AND PortTypeId = 1
Select DateArrived, PortId From tbTrackPort Where TrackPortId = @portid

Thanks for any help you can give.

Best Regards,

Always Learning.

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-11-12 : 07:13:14
Do you mean linq?
Go to Top of Page

Steve2106
Posting Yak Master

183 Posts

Posted - 2014-11-12 : 08:24:33
Hi There,

Thanks for the reply.

Not sure if it's linq or lambda. It looks something like this:

var trackApprovers = this.approves.Where(x => x.TrackID == td.TrackID);
if(!trackApprovers.Any())
return null;
if (trackApprovers.Count(x => x.Approved == true) == trackApprovers.Count())
{
return trackApprovers.OrderByDescending(x => x.ChangedDate).FirstOrDefault().ChangedDate;
}

Thanks for your help.

Best Regards,



Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-11-12 : 09:14:45
You're using LINQ in C#. I think that the first part of your query is redundant:


select @portid = PORTSID from tbPortActions
where PortID =
(select PortID from tbPortActions where PORTSID = 5843)


is this not the same as "SET @portid = 5843" ???
Go to Top of Page
   

- Advertisement -