How to create a DbFunctionCall for REPLICATE?

Posts   
 
    
gabrielk avatar
gabrielk
User
Posts: 231
Joined: 01-Feb-2005
# Posted on: 07-Apr-2010 11:31:24   

Hi,

I've got a varchar column that I would like to sort padded, to end up with:

30 200 250

Instead of:

200 250 30

Therefore I would use:

REPLICATE('0', ( 10 - LEN(Number) ) ) + Number AS PaddedNumber

In SQL, but I've no clue how to create the DBFunctionCall parameter for this. I can create a nested one, but the combined parameter '10 - LEN(Number)' and the combination of 'REPLICATE (...) + Number' are a mystery to me.

Please help,

Thanks.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 07-Apr-2010 11:36:06   

REPLICATE('0', ( 10 - LEN(Number) ) ) + Number AS PaddedNumber

Try this please:

new DbFunctionCall(
    "REPLICATE ('0', ( 10 - LEN({0}) ) ) + {0}  AS PaddedNumber", new object[] { MyEnitityFields.Number});

(Edit) Or

new DbFunctionCall(
    "REPLICATE ('0', ( 10 - LEN({0}) ) ) + {0}", new object[] { MyEnitityFields.Number});