|
Home > Archive > MS SQL Server > December 2005 > User Defined Data type Problem
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
User Defined Data type Problem
|
|
|
| Hi Friends,
I have a small problem hoping that you experts can resolve it. I need
to make a user defined data type for a field. My field name is
FINDG_NO(PK) and its datatype needs to be
(Five fillers alphabatic then today's date, and then two fillers at the
end alphanumeric)
Here is the example:
ABCDE12/29/05N2.
The date should come automatic each time the new record is being
entered. the fillers needs to be filled by user.
Can someone help me pleaseeeeeeeee
Moe
| |
| Amish Shah 2005-12-30, 7:23 am |
| May this one help you
create table test
(val varchar(100) not null,
data varchar(100))
alter table test
add constraint pk_val primary key (val)
create trigger testtrig on test
instead of insert
as
begin
declare @id int
select @id = len(val) from inserted
if @id <> 7
rollback
else
insert into test select left(val,5) + convert(char(10), getdate(),103) +
right(val,2),data
from inserted
end
insert into test values('ABCDEN2','th
is is a sample')
Regards
Amish
*** Sent via Developersdex http://www.droptable.com ***
| |
|
| Thanks Amish, i tried this and it didnt work. This is the first time i
am working with sql server so please bear with me. Is there any way i
can do something in the User Defined Data Type. I was going through Pub
Database in sql and it has some UserDefinedDataTypes
. Can you tell me
something like this or the code of how to do it. Or i can simply go
into table's properity and in Constraint i can write some code so that
the FINDG_NO field can only take that type of data in the same format
as mentioned in my first message.
Please help me freind.
Thanks
Moe
| |
| Tibor Karaszi 2005-12-31, 3:23 am |
| User defined datatype, default, rules or the more modern concepts "constraints" will not help you
here as all they does is to constraint what information you are allowed. They do not change things
for you.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www. solidqualitylearning
.com/
Blog: http:// solidqualitylearning
.com/blogs/tibor/
"Moe" <October.April@gmail.com> wrote in message
news:1135980841.024236.309190@o13g2000cwo.googlegroups.com...
> Thanks Amish, i tried this and it didnt work. This is the first time i
> am working with sql server so please bear with me. Is there any way i
> can do something in the User Defined Data Type. I was going through Pub
> Database in sql and it has some UserDefinedDataTypes
. Can you tell me
> something like this or the code of how to do it. Or i can simply go
> into table's properity and in Constraint i can write some code so that
> the FINDG_NO field can only take that type of data in the same format
> as mentioned in my first message.
>
> Please help me freind.
>
> Thanks
> Moe
>
| |
|
| It should work
what problem you face in the script or can you tell me what data you
get in the table after running the script.
Regards
Amish
|
|
|
|
|