sql - TSQL Computed column limitations -


create table [dbo].[membershipmodule](  [id] [uniqueidentifier] rowguidcol  not null,  [parentid] [uniqueidentifier] null,  [targetid] [int] null,  [webcontentid] [uniqueidentifier] null,  [name] [varchar](35) not null,  [nameupper]  (isnull(upper([name]),'')) persisted not null,  [uriprefix] [varchar](max) null,  [uritext] [varchar](max) null,  [uricomputed]  ??? persisted,  [description] [varchar](100) null,  [created] [date] not null,  [modified] [datetime2](7) not null,  [menuitem] [bit] not null,  [enabled] [bit] not null,  [position] [smallint] null,  constraint [pk_membershipmodule] primary key clustered  (  [id] asc )with (pad_index  = off, statistics_norecompute  = off, ignore_dup_key = off, allow_row_locks  = on, allow_page_locks  = on) on [primary] ) on [primary] 

so far uricomputed field computed this:

lower(replace(isnull([uriprefix],'/')+coalesce([uritext],[name]),' ','-')) 

this produces output following

results

now, i'd want terminate uricomputed values '/'. accomplished adding + '/' computed field, except fact "textless" uris, terminated //, don't want happening.

since sql can put computed field quite limited (and don't know extents of these limitations) thought i'd ask here how add this.

basically want output in image be

/a/login/ /a/announcements/ /a/ / 

my closest attempt @ doing has been:

isnull(convert(varchar(max),nullif(len(coalesce([uritext],[name])),0)),'/') 

which kind of mess, , adds number if should terminate in '/', , adds '/' when should, i'd need opposite ( is, '/' when length 0, '' otherwise)

if there's inline if or use it, don't know that.

thank you!

this worked me:

[uricomputed]  (case                       when right(lower(replace(isnull([uriprefix],'/')+coalesce([uritext],[name]),' ','-')), 1) = '/'                        lower(replace(isnull([uriprefix],'/')+coalesce([uritext],[name]),' ','-'))                      else                        lower(replace(isnull([uriprefix],'/')+coalesce([uritext],[name]),' ','-')) +'/'                    end) persisted, 

full create table statement:

create table [dbo].[membershipmodule](  [id] [uniqueidentifier] rowguidcol  not null,  [parentid] [uniqueidentifier] null,  [targetid] [int] null,  [webcontentid] [uniqueidentifier] null,  [name] [varchar](35) not null,  [nameupper]  (isnull(upper([name]),'')) persisted not null,  [uriprefix] [varchar](max) null,  [uritext] [varchar](max) null,  [uricomputed]  (case                       when right(lower(replace(isnull([uriprefix],'/')+coalesce([uritext],[name]),' ','-')), 1) = '/'                        lower(replace(isnull([uriprefix],'/')+coalesce([uritext],[name]),' ','-'))                      else                        lower(replace(isnull([uriprefix],'/')+coalesce([uritext],[name]),' ','-')) +'/'                     end) persisted,  [description] [varchar](100) null,  [created] [date] not null,  [modified] [datetime2](7) not null,  [menuitem] [bit] not null,  [enabled] [bit] not null,  [position] [smallint] null) 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -