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.
Author |
Topic |
incxbxs
Starting Member
7 Posts |
Posted - 2010-12-24 : 08:10:16
|
Hello, i want to do such an operation @subject= 'Project' + @lastInsert_ProjectName where @subject and @lastInsert_ProjectName is variables. and 'Project' is string.But i could'not manage to put ' ' in correct places. Even i read the article here i didnot understand the idea.[url]http://sqlblogcasts.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx[/url]Sorry for the beginner questions but i'm a beginner though:)Thanks,Alper |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-12-24 : 09:12:21
|
So you want single quotes as part of the string?Each single qoute that is needed inside a string has to be escaped by another single quote.@subject='''Project''' + @lastInsert_ProjectName No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
incxbxs
Starting Member
7 Posts |
Posted - 2010-12-24 : 11:29:14
|
[quote]Originally posted by webfred So you want single quotes as part of the string?Each single qoute that is needed inside a string has to be escaped by another single quote.@subject='''Project''' + @lastInsert_ProjectName No, you're never too old to Yak'n'Roll if you're too young to die.[/quoteNo, Just Project + content of variable.i tried 'Project' + @variable but it doesnot work. It says incorrect syntax near + |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-12-24 : 12:51:13
|
Show the actual statement please. What you showed us ought to work.declare @a varchar(12)declare @b varchar(12)set @a = 'world'set @b = 'hello ' + @aselect @b |
|
|
incxbxs
Starting Member
7 Posts |
Posted - 2010-12-25 : 16:03:48
|
CREATE TRIGGER [dbo].[InitialProjectNotification]ON [dbo].[Project]AFTER INSERTASDECLARE @Message_Subject varchar(100)DECLARE @lastInsert_ManagerID intDECLARE @lastInsert_ProjectName varchar(100)SET @lastInsert_ManagerID = (select Project_Manager_ID from inserted)SET @lastInsert_ProjectName = (select Project_Name from inserted)EXECUTE MessageInsert @Message_Owner_ID = @lastInsert_ManagerID, @Message_Subject = 'Project' + @lastInsert_ProjectName, @Message_Body = 'You Successfully Add Project' + @lastInsert_Project_Name, @Message_Date = '1988-05-06 00:00:00', @Message_Sender_ID=@lastInsert_ManagerID,@Message_IsRead=0EXECUTE msdb.dbo.sp_send_dbmail@profile_name='alper-tasadar',@recipients='xxx@yyy.com',@subject='Project' + @lastInsert_ProjectName,@body='This is the body of the test message.Congrates Database Mail Received By you Successfully.' |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-12-26 : 11:57:14
|
[code]CREATE TRIGGER [dbo].[InitialProjectNotification]ON [dbo].[Project]AFTER INSERTASDECLARE @Message_Subject varchar(100)DECLARE @lastInsert_ManagerID intDECLARE @lastInsert_ProjectName varchar(100)DECLARE @Message_Body Varchar(100)DECLARE @subject Varchar(100)SET @lastInsert_ManagerID = (select Project_Manager_ID from inserted)SET @lastInsert_ProjectName = (select Project_Name from inserted)SET @Message_Subject = 'Project' + @lastInsert_ProjectNameSET @Message_Body = 'You Successfully Add Project' + @lastInsert_ProjectNameSET @subject = 'Project' + @lastInsert_ProjectNameEXECUTE MessageInsert @Message_Owner_ID = @lastInsert_ManagerID, @Message_Subject = @Message_Subject, @Message_Body = @Message_Body, @Message_Date = '1988-05-06 00:00:00', @Message_Sender_ID = @lastInsert_ManagerID, @Message_IsRead = 0EXECUTE msdb.dbo.sp_send_dbmail @profile_name = 'alper-tasadar', @recipients = 'xxx@yyy.com', @subject = @subject, @body = 'This is the body of the test message. Congrates Database Mail Received By you Successfully.'[/code] |
|
|
incxbxs
Starting Member
7 Posts |
Posted - 2010-12-30 : 07:16:14
|
Thank you for your help!it is working now.sorry for the late feedback, i was abroad.Regards,Alper |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-12-30 : 11:54:58
|
You're welcome. And welcome back, hope it was a good trip. |
|
|
|
|
|
|
|