Showing posts with label statment. Show all posts
Showing posts with label statment. Show all posts

Monday, February 27, 2012

help me....

hi everyone

i got 2 questions plz

1- how to use the datadiff function ....plz write the code

2- is there a Trim function or statment that cuts the unneeded spaces before and after the word

thanx ...

Hi there,
1. http://msdn.microsoft.com/library/en-us/tsqlref/ts_da-db_5vxi.asp?frame=true
samples imcluded :-)
2. What do you mean by unneeded ? You can trail characters, by using the function which I wrote some time ago:
CREATE FUNCTION dbo.fn_removetrailingchars
(
@.strValue VARCHAR(200),
@.TrailingChar VARCHAR(200),
@.RemoveLeading BIT
)
--Coded by Jens Suessmeyer, 2005 Available on http://www.sqlserver2005.de
RETURNS VARCHAR(200)
AS
BEGIN


DECLARE @.intCount int
SET @.intCount = 0


WHILE @.intCount <= LEN(@.strValue)
BEGIN
SET @.intCount = @.intCount +1
IF SUBSTRING(@.strValue, @.intCount, 1) NOT LIKE @.TrailingChar
BREAK
ELSE
CONTINUE
END
IF @.RemoveLeading = 1
SET @.strValue =
REVERSE(dbo.fn_removetrailingchars(REVERSE(RIGHT(@.strValue,
LEN(@.strValue) - @.intCount +1 )),@.TrailingChar,0))
ELSE
SET @.strValue = RIGHT(@.strValue, LEN(@.strValue) - @.intCount +1
)


RETURN @.strValue
END

Could be called by: Select dbo.fn_removetrailingchars (SomeColumn,CHAR(32),1) FROM Sometable


HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

|||

thanx for answering

but what i mean is a function or starment Called trim which removes the spaces ....and i think it should be used in the insertion

for an example lets say wa have a string " hi " i want to remove the spaces before and after hi

so how can i use it ?

|||Hi,

if you don't want to use my function, simply use LTRIM(RTRIM(Expression))

HTH, jens Suessmeyer.

http://www.sqlserver2005.de

Sunday, February 19, 2012

Help me Please to Create this TRIGGER

Hi everybody,

How can I Update a field from another table by Trigger? Can someone send me the statment to do it?

I have a table called Clients with fields : ID_Clients, Client
And Another called Doc with fields : ID_Doc, ID_Clients, Client

These tables are in different databases and I would like to esure the integrity by add a Trigger to update in Docs table the field Client everytime its changed in the Clients table.

Thanks for Attetion.

Leonardo AlmeidaThis is not a forum for tutorials.

Here is some sample code:

CREATE TRIGGER YourTrigger ON dbo.YourTable
FOR UPDATE
AS
update DBName.DBTable
set YourField = inserted.YourField
from DBName.DBTable
inner join inserted on DBName.DBTable.KeyField = inserted.KeyField

Please read about triggers in Books Online and then post again if you have a specific question.

blindman

Help me create this Trigger


Hi everybody,

How can I Update a field from another table by Trigger? Can someone send
me the statment to do it?

I have a table called Clients with fields : ID_Clients, Client
And Another called Doc with fields : ID_Doc, ID_Clients, Client

These tables are in different databases and I would like to esure the
integrity by add a Trigger to update in Docs table the field Client
everytime its changed in the Clients table.

Thanks for Attetion.

Leonardo Almeida

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!"Leonardo Almeida" <leonardoalmeida2004@.yahoo.com.br> wrote in message
news:3f672aa2$0$62077$75868355@.news.frii.net...
>
> Hi everybody,
> How can I Update a field from another table by Trigger? Can someone send
> me the statment to do it?
> I have a table called Clients with fields : ID_Clients, Client
> And Another called Doc with fields : ID_Doc, ID_Clients, Client
> These tables are in different databases and I would like to esure the
> integrity by add a Trigger to update in Docs table the field Client
> everytime its changed in the Clients table.
> Thanks for Attetion.
> Leonardo Almeida
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

Something like this should work:

create trigger dbo.ATR_U_Clients
on dbo.Clients
after update
as

if @.@.rowcount = 0
return

update OtherDatabase.dbo.Doc
set Client = i.Client
from OtherDatabase.dbo.Doc d
join inserted i
on d.ID_Clients = i.ID_Clients

Simon