[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.sqlserver.programming

Declaring size when concatenating fields in a view

wawork

3/29/2007 12:07:00 AM

Beginer's question.

I have a view where I'm concatenating the lating names for genus and
species to create a virtual field named Scientific_Name. Because the
latin name is defined as 40 characters the resulting virtual field is
80. Is there a way to define the virtual filed to 50 for example?
I'm not worry about the concatenated string being longer than 50.

CREATE view v_TAXO_SciName as
select
T1.TAXO_NAME_Id,
T1.Primary_Common_Name as Common_Name,
case
when T1.TAXO_CATGRY_TYPE_Code = 70 then T3.Latin_Name + ' ' +
T2.Latin_Name + ' ' + T1.Latin_Name
when T1.TAXO_CATGRY_TYPE_Code = 60 then T3.Latin_Name + ' ' +
T2.Latin_Name
end 'Scientific_Name',
T4.latin_name as Class_Name,
T1.TAXO_CATGRY_TYPE_Code
from
TAXO_NAME T1,
TAXO_MGMNT_LEVEL L,
TAXO_NAME T2,
TAXO_NAME T3,
TAXO_NAME T4
where
T1.TAXO_NAME_Id = L.TAXO_NAME_Id
and L.Species_Num =T2.TAXO_NAME_Id
and L.Genus_Num =T3.TAXO_NAME_Id
and L.Class_Num =T4.TAXO_NAME_Id
and (T1.TAXO_CATGRY_TYPE_Code = 70 or T1.TAXO_CATGRY_TYPE_Code = 60)
2 Answers

xyb

3/29/2007 1:34:00 AM

0

On 3?29?, ??8?07?, waw...@hotmail.com (Randy K) wrote:
> Beginer's question.
>
> I have a view where I'm concatenating the lating names for genus and
> species to create a virtual field named Scientific_Name. Because the
> latin name is defined as 40 characters the resulting virtual field is
> 80. Is there a way to define the virtual filed to 50 for example?
> I'm not worry about the concatenated string being longer than 50.
>
> CREATE view v_TAXO_SciName as
> select
> T1.TAXO_NAME_Id,
> T1.Primary_Common_Name as Common_Name,
> case
> when T1.TAXO_CATGRY_TYPE_Code = 70 then T3.Latin_Name + ' ' +
> T2.Latin_Name + ' ' + T1.Latin_Name
> when T1.TAXO_CATGRY_TYPE_Code = 60 then T3.Latin_Name + ' ' +
> T2.Latin_Name
> end 'Scientific_Name',
> T4.latin_name as Class_Name,
> T1.TAXO_CATGRY_TYPE_Code
> from
> TAXO_NAME T1,
> TAXO_MGMNT_LEVEL L,
> TAXO_NAME T2,
> TAXO_NAME T3,
> TAXO_NAME T4
> where
> T1.TAXO_NAME_Id = L.TAXO_NAME_Id
> and L.Species_Num =T2.TAXO_NAME_Id
> and L.Genus_Num =T3.TAXO_NAME_Id
> and L.Class_Num =T4.TAXO_NAME_Id
> and (T1.TAXO_CATGRY_TYPE_Code = 70 or T1.TAXO_CATGRY_TYPE_Code = 60)

you can use LEFT function for specified length.

Aaron [SQL Server MVP]

3/29/2007 3:34:00 AM

0

Scientific_Name = CONVERT(VARCHAR(50), CASE WHEN ... END),

--
Aaron Bertrand
SQL Server MVP
http://www.sq...
http://www.aspfa...




"Randy K" <wawork@hotmail.com> wrote in message
news:460b0182.88144937@msnews.microsoft.com...
> Beginer's question.
>
> I have a view where I'm concatenating the lating names for genus and
> species to create a virtual field named Scientific_Name. Because the
> latin name is defined as 40 characters the resulting virtual field is
> 80. Is there a way to define the virtual filed to 50 for example?
> I'm not worry about the concatenated string being longer than 50.
>
> CREATE view v_TAXO_SciName as
> select
> T1.TAXO_NAME_Id,
> T1.Primary_Common_Name as Common_Name,
> case
> when T1.TAXO_CATGRY_TYPE_Code = 70 then T3.Latin_Name + ' ' +
> T2.Latin_Name + ' ' + T1.Latin_Name
> when T1.TAXO_CATGRY_TYPE_Code = 60 then T3.Latin_Name + ' ' +
> T2.Latin_Name
> end 'Scientific_Name',
> T4.latin_name as Class_Name,
> T1.TAXO_CATGRY_TYPE_Code
> from
> TAXO_NAME T1,
> TAXO_MGMNT_LEVEL L,
> TAXO_NAME T2,
> TAXO_NAME T3,
> TAXO_NAME T4
> where
> T1.TAXO_NAME_Id = L.TAXO_NAME_Id
> and L.Species_Num =T2.TAXO_NAME_Id
> and L.Genus_Num =T3.TAXO_NAME_Id
> and L.Class_Num =T4.TAXO_NAME_Id
> and (T1.TAXO_CATGRY_TYPE_Code = 70 or T1.TAXO_CATGRY_TYPE_Code = 60)