Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Is this possible?

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2008-02-15 : 23:19:44
Hello,

I have a table with 3 columns:
FileID, Description and Path

FileID is a Guid and created using NewID()
I am inserting records in the database using LINQ.

Is it possible inside my table to do the following?

When inserting a record if path contains the string $Guid$ then $Guid$ should be replaced by FileID value, i.e., the generated Guid.

Can I do this?

Maybe with a trigger or something ...

Thanks,
Miguel

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-02-15 : 23:34:08
what path?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-16 : 01:14:05
REPLACE(path,'$Guid$',FileID) is probably what you are looking at. b/w what is datatype of path field?
Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2008-02-16 : 07:29:12
The type of Path is a NVarChar.

But how can I create a SQL Script that creates the trigger that fires on insert and on update and perform that action?

I use a script to create all my tables. For example:

create table dbo.Files
(
FileID uniqueidentifier ROWGUIDCOL not null
default NewID()
constraint PK_File primary key clustered,
[Description] nvarchar(400),
[Filename] nvarchar(800) not null
)

I am doing this to avoid accessing my database twice from my code.

Thanks,
Miguel
Go to Top of Page
   

- Advertisement -