Hi,
I need to format a data in the given format.
AAA-AAA-AAA Where AAA stands for any alphanumerice.
For eg. I am looking for something like this.
FORMAT('AAA-AAA-AAA','ABCDEFGHI') Should return ABC-DEF-GHI
I can get the above info using the below given sql,
Select
SUBSTRING(Field1,1,3)+'-'+SUBSTRING(Field2,4,3)+'-'+SUBSTRING(Field3,7,3)
from Table
Any other alternatives?
What is the best way to achieve this?
Thanks & Regards,
AshishFormatting should always be a client side task.
No alternatives.
HTH, Jens Suessmeyer.
"Ashish P K" <AshishP@.icode.com> schrieb im Newsbeitrag
news:%23XttOQ%23SFHA.208@.TK2MSFTNGP10.phx.gbl...
> Hi,
> I need to format a data in the given format.
> AAA-AAA-AAA Where AAA stands for any alphanumerice.
> For eg. I am looking for something like this.
> FORMAT('AAA-AAA-AAA','ABCDEFGHI') Should return ABC-DEF-GHI
> I can get the above info using the below given sql,
> Select
> SUBSTRING(Field1,1,3)+'-'+SUBSTRING(Field2,4,3)+'-'+SUBSTRING(Field3,7,3)
> from Table
> Any other alternatives?
> What is the best way to achieve this?
> Thanks & Regards,
> Ashish
>|||You could store the format mask in an extended property for the column, then
on the client side reference the extended property.
Not sure if I agree with the below statement ... there are always
alternatives. You could for example add an additional computed column to th
e
table that returns the data in the format you want to enforce or use a view.
If you are worried about different programmers displaying formatted data
inconsistently then formatting it as part of the result set is definitely a
way to create a consistent format of data across applications.
"Jens Sü?meyer" wrote:
> Formatting should always be a client side task.
> No alternatives.
> HTH, Jens Suessmeyer.
> "Ashish P K" <AshishP@.icode.com> schrieb im Newsbeitrag
> news:%23XttOQ%23SFHA.208@.TK2MSFTNGP10.phx.gbl...
>
>|||"Chris Stransky" <ChrisStransky@.discussions.microsoft.com> wrote in message
news:0AA9C3F9-1FCB-4CA7-9808-48362B172CAF@.microsoft.com...
> You could store the format mask in an extended property for the column,
> then
> on the client side reference the extended property.
> Not sure if I agree with the below statement ... there are always
> alternatives. You could for example add an additional computed column to
> the
> table that returns the data in the format you want to enforce or use a
> view.
> If you are worried about different programmers displaying formatted data
> inconsistently then formatting it as part of the result set is definitely
> a
> way to create a consistent format of data across applications.
I don't agree with this part.
I have functions client side that handle all formatting: currency, dates,
telephone numbers...
All programmers use these functions in our ASP pages.
The functions also format data depending on user language.
At least this way, if management wants to change formatting, let's say for
dates, I need only to modify the function that handles this, not look at all
tables that have a datetime column.
Showing posts with label alphanumerice. Show all posts
Showing posts with label alphanumerice. Show all posts
Monday, March 12, 2012
Formating Strings using SQL
Subscribe to:
Posts (Atom)