The expression contains undefined function call REPLACE()

Hi

I am creating a datacolumn in which I am assigning the value of expression

"REPLACE(CONVERT(VARCHAR(11), my_date, 106), ' ', '-') +' - '+ my_series"

but I am getting an error - "The expression contains undefined function call REPLACE()"

After I have removed Replace I am getting the error for varchar.

How can I convert the date in that format - 01-Apr-2010

Kindly advice.


Regards
Karan
KaranGuptaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cascader_grCommented:
You can't use T-SQL (MS SQL Server) syntax in the compute expression of a .Net data column. What is the format you want to apply to the date column?
0
KaranGuptaAuthor Commented:
Hi cascader_gr

01-Apr-2010


Regards
Karan
0
cascader_grCommented:
I can't see an easy way to do this. The reason is that Expression property is for calculation rather than formatting (although I understand it's not just formatting you are after). Here are my suggestions:

If you need to do that in .Expression, you will have to change (event temporarily) the culture of your thread:
Dim ci as CultureInfo = CultureInfo.CurrentCulture.Clone()
ci.DateTimeFormat.ShortDatePattern = "dd-MMM-yyyy"
Thread.CurrentThread.CurrentCulture = ci

after the above, you can use: .Expression = "Convert(my_date, 'System.String') + my_series"

But I suggest you either:
* handle the row adding event of the dataset and set the column's value there
or
* If you don't need to persist the resulting value and you only need it for display purposes, do that on the presentation layer (i.e. when DataBinding the textbox control or grid column).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
halfbloodprinceCommented:
THIS WORKS!!! Am assuming you want to do this in .NET.
==================================================================================
 Dim objDate As Date
        Dim strDate As String
        objDate = Now()

        strDate = String.Format("{0:dd-MMM-yyyy}", objDate)
        Response.Write(strDate)
=================================================================================
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.