i’m having a problem with my database. I have the folowing:
create table book
(
name_b varchaR(50) primary key,
typee varchaR(50) not null,
nmbr integer unique not null,
yeare numeric(4,0) default null,
)
create table story
(
id integer identity(1,1) primary key,
name_s varchar(100) not null,
chars varchar(100) not null,
code varchaR(200) null,
artist varchar(100) default null,
argument varchar(100) default null,
book_ref_name varchar(50) references book(name_b),
book_ref_nmbr integer references book(nmbr)
)
insert into story values
('StoryName1','StoryChars1',null,default,default,'BookName1',13),
('StoryName2','StoryChars2',null,default,default,'BookName2',35),
('StoryName3','StoryChars3',null,default,default,'BookName3',125)
insert into book values
('BookName1','Type1',13,default),
('BookName2','Type2',35,default),
('BookName3','Type3',125,default)
what i want with this is the STORY.CODE to be replaced from NULL to a junction of strings for example imagine the first entry of the STORY table
('StoryName1','StoryChars1',null,default,default,'BookName1',13)
in this case i would like the STORY.CODE to be replaced with ‘StoryName1-StoryChars1-BookName1-13’.
is this even possible? if it isn’t whats the nearest possibility of something similar?
thx in advance
another doubt i have, how can i make a SELECT statement that selects * from STORY except the null fields. for example if a story has no argumentist/artist i dont want that field to show up.
If you want to do this via an
UPDATEVia an
INSERTyou basically do something similar:Or you can use a
CASEAs far as your second question regarding the
SELECT, I think this is what you need