Showing posts with label querythe. Show all posts
Showing posts with label querythe. Show all posts

Monday, March 19, 2012

Formatting Dates as YYYY/MM/DD for a particular query

Anyone know how to format dates from 10/3/05 to 2005/10/03 in a query?
The only way I know is (cast(year(srecordeddate) as char(4)))+ cast('/'as char) + cast (month(srecordeddate) as char(2))... Which seems so rediculous. There's gotta be a better way!select convert(varchar(10), getdate(), 111)|||Anyone know how to format dates from 10/3/05 to 2005/10/03 in a query?

The only way I know is (cast(year(srecordeddate) as char(4)))+ cast('/'as char) + cast (month(srecordeddate) as char(2))... Which seems so rediculous. There's gotta be a better way!

With the caveat that it's almost ALWAYS better to handle formatting on the client side, you might try:

Convert(varchar(10), [YourDate], 120)

Regards,

hmscott|||select convert(varchar(10), getdate(), 111)
Thanks! You've bailed me out of another toughee...

Friday, March 9, 2012

Format the column with

Hello,
Can you tell me how can i format the column with in the output of a query?
The results must be returned as text and my output is like this:
y x
-- --
1 2
the way im treating the output is to cast the field as varchar(xxx):
select cast(y as varchar(1)), cast(x as varchar(1))
from xxxxxx
y x
- -
1 2
It is possible to do it with a different way?
Thanks and best regards.
Hi
SELECT coalesce(x,'')+coalesce(y,'') as blabla
"CC&JM" <CCJM@.discussions.microsoft.com> wrote in message
news:5386EC39-E9F2-4D5E-A965-E9BFF9984D3E@.microsoft.com...
> Hello,
> Can you tell me how can i format the column with in the output of a query?
> The results must be returned as text and my output is like this:
> y x
> -- --
> 1 2
> the way im treating the output is to cast the field as varchar(xxx):
> select cast(y as varchar(1)), cast(x as varchar(1))
> from xxxxxx
> y x
> - -
> 1 2
> It is possible to do it with a different way?
> Thanks and best regards.
|||SQL Server returns meta-data with the result set. This meta-data includes information about the
datatype for each columns. A tool like Query Analyzer uses this meta-data to define the length of
the columns presented. Note that when you execute into grid, things are different. The columns are
indeed made smaller to include more information in what you see. So, in other words, what you see if
done by the client application, not SQL server itself.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"CC&JM" <CCJM@.discussions.microsoft.com> wrote in message
news:5386EC39-E9F2-4D5E-A965-E9BFF9984D3E@.microsoft.com...
> Hello,
> Can you tell me how can i format the column with in the output of a query?
> The results must be returned as text and my output is like this:
> y x
> -- --
> 1 2
> the way im treating the output is to cast the field as varchar(xxx):
> select cast(y as varchar(1)), cast(x as varchar(1))
> from xxxxxx
> y x
> - -
> 1 2
> It is possible to do it with a different way?
> Thanks and best regards.
|||Thanks Uri,
Best regards
"Uri Dimant" wrote:

> Hi
> SELECT coalesce(x,'')+coalesce(y,'') as blabla
>
> "CC&JM" <CCJM@.discussions.microsoft.com> wrote in message
> news:5386EC39-E9F2-4D5E-A965-E9BFF9984D3E@.microsoft.com...
>
>

Format the column with

Hello,
Can you tell me how can i format the column with in the output of a query?
The results must be returned as text and my output is like this:
y x
-- --
1 2
the way im treating the output is to cast the field as varchar(xxx):
select cast(y as varchar(1)), cast(x as varchar(1))
from xxxxxx
y x
- -
1 2
It is possible to do it with a different way?
Thanks and best regards.Hi
SELECT coalesce(x,'')+coalesce(y,'') as blabla
"CC&JM" <CCJM@.discussions.microsoft.com> wrote in message
news:5386EC39-E9F2-4D5E-A965-E9BFF9984D3E@.microsoft.com...
> Hello,
> Can you tell me how can i format the column with in the output of a query?
> The results must be returned as text and my output is like this:
> y x
> -- --
> 1 2
> the way im treating the output is to cast the field as varchar(xxx):
> select cast(y as varchar(1)), cast(x as varchar(1))
> from xxxxxx
> y x
> - -
> 1 2
> It is possible to do it with a different way?
> Thanks and best regards.|||SQL Server returns meta-data with the result set. This meta-data includes in
formation about the
datatype for each columns. A tool like Query Analyzer uses this meta-data to
define the length of
the columns presented. Note that when you execute into grid, things are diff
erent. The columns are
indeed made smaller to include more information in what you see. So, in othe
r words, what you see if
done by the client application, not SQL server itself.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"CC&JM" <CCJM@.discussions.microsoft.com> wrote in message
news:5386EC39-E9F2-4D5E-A965-E9BFF9984D3E@.microsoft.com...
> Hello,
> Can you tell me how can i format the column with in the output of a query?
> The results must be returned as text and my output is like this:
> y x
> -- --
> 1 2
> the way im treating the output is to cast the field as varchar(xxx):
> select cast(y as varchar(1)), cast(x as varchar(1))
> from xxxxxx
> y x
> - -
> 1 2
> It is possible to do it with a different way?
> Thanks and best regards.|||Thanks Uri,
Best regards
"Uri Dimant" wrote:

> Hi
> SELECT coalesce(x,'')+coalesce(y,'') as blabla
>
> "CC&JM" <CCJM@.discussions.microsoft.com> wrote in message
> news:5386EC39-E9F2-4D5E-A965-E9BFF9984D3E@.microsoft.com...
>
>