January 26, 2008 at 11:16 am
I'm trying to populate a table of pending emails. The problem is I need to populate the email field using a select statement but the message field with static text. Can this be done or is another approach more prudent? What I have is below but is kicking errors:
DECLARE @msg varchar(300)
SET @msg = 'New users have applied for accounts. Please review their information.'
IF @Type='CreateUserApply'
INSERT INTO cdds_Email (Address,Message)
VALUES (SELECT
M.Email
FROM
dbo.aspnet_Membership M
INNER JOIN
dbo.aspnet_UsersInRoles U
INNER JOIN
dbo.aspnet_Roles R
ON
U.RoleId = R.RoleId
ON
U.UserId = M.UserId
WHERE
R.RoleName = 'Manager',@msg)
January 26, 2008 at 11:29 am
The Insert into ... select is what you need. There's no problems with including variables or constants in the select clause of a select statement.
Insert into TheTBL (ColumnList)
SELECT M.Email, @msg AS Message
FROM .....
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 28, 2008 at 7:08 am
Thank you so much! I knew it was something silly but I couldn't come up with the correct syntax.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply