Can I do this sp with LLBLGen?

Posts   
 
    
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 18-Oct-2006 17:06:10   

Hi,

Is it possible to do this without using a stored procedure or alot of custom code...


ALTER PROCEDURE [dbo].[sp_GetTopLifeNStuffCategory]

@Date as datetime

AS

SELECT

c.LifeNStuffCategoryID,
Title,
Ordinal,
LifeNStuffPriorityID,
CASE WHEN startdate IS NULL THEN NULL ELSE 1 END AS 'IsPriortiy'

FROM

tbl_lifenstuff_category c

LEFT JOIN

tbl_Lifenstuffpriority p

ON

c.LifeNStuffCategoryID = p.LifeNStuffCategoryID
AND
p.startdate <= @Date AND p.enddate > @Date

ORDER BY

IsPriortiy DESC,
ordinal

Its the 'case' statement that's the problem.

Cheers, Ian.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 18-Oct-2006 17:08:35   

I think you pasted the wrong proc, this one doesn't have a case statement wink

Frans Bouma | Lead developer LLBLGen Pro
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 18-Oct-2006 18:11:01   

Well wrong version. I added it back in.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 18-Oct-2006 19:20:23   

Ian wrote:

Well wrong version. I added it back in.

Ok. Yes you can do this, but not with CASE, you can use a DbFunctionCall expression (v2.0) and call COALESCE() to make the case logic possible.

Frans Bouma | Lead developer LLBLGen Pro
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 18-Oct-2006 20:04:43   

I'm not sure COALESCE will work here. That function returns the first non-null value. I want null if the value is null or 1 otherwise.

(Its so that the first sort field partitions the results into the rows that have joined with the right table followed by those that haven't. )

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 19-Oct-2006 06:21:30   

Have you considered using client-side sorting?

Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 19-Oct-2006 15:25:04   

Yup. But I'm happy to leave it as a stored procedure. sunglasses