Question : I need to create stored procedure to show sent messages.

USE [omegalove]
GO

/****** Object:  Table [dbo].[tbl_Messages]    Script Date: 08/21/2010 13:16:27 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[tbl_Messages](
      [MessageID] [int] IDENTITY(1,1) NOT NULL,
      [ProfileID] [int] NOT NULL,
      [FromProfileID] [int] NULL,
      [FromUsername] [nvarchar](50) NULL,
      [Subject] [nvarchar](50) NULL,
      [Body] [nvarchar](max) NULL,
      [MsgDate] [datetime] NULL,
      [MsgRead] [int] NULL,
      [MsgReplied] [int] NULL,
      [MsgNew] [int] NULL,
      [ReplyOfMessageID] [int] NULL,
      [InitialMessageID] [int] NULL,
 CONSTRAINT [PK_tbl_Messages] PRIMARY KEY CLUSTERED
(
      [MessageID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[tbl_Messages] ADD  CONSTRAINT [DF_tbl_Messages_MsgDate]  DEFAULT (getdate()) FOR [MsgDate]
GO

ALTER TABLE [dbo].[tbl_Messages] ADD  CONSTRAINT [DF_tbl_Messages_MsgRead]  DEFAULT ((0)) FOR [MsgRead]
GO

ALTER TABLE [dbo].[tbl_Messages] ADD  CONSTRAINT [DF_tbl_Messages_MsgReplied]  DEFAULT ((0)) FOR [MsgReplied]
GO

ALTER TABLE [dbo].[tbl_Messages] ADD  CONSTRAINT [DF_Messages_MsgNew]  DEFAULT ((0)) FOR [MsgNew]
GO

ALTER TABLE [dbo].[tbl_Messages] ADD  CONSTRAINT [DF_tbl_Messages_ReplyOfMessageID]  DEFAULT ((0)) FOR [ReplyOfMessageID]
GO

ALTER TABLE [dbo].[tbl_Messages] ADD  CONSTRAINT [DF_tbl_Messages_InitialMessageID]  DEFAULT ((0)) FOR [InitialMessageID]
GO


Answer : I need to create stored procedure to show sent messages.

okay last time for now, I promise, I forgot to select your extra column.  See attached please.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
ALTER PROCEDURE [dbo].[prc_Messages_Sent_Select_All]
	@FromProfileID INT

AS
BEGIN
	SET NOCOUNT ON
	
    SELECT
		a.[MessageID],
		a.[ProfileID],
		a.[FromProfileID],
		a.[FromUsername],
		b.[UserName] AS SentToUserName,
		a.[Subject],
		a.[Body],
		convert(varchar, a.[MsgDate], 107) AS zdate,
		a.[MsgDate],
		a.[MsgRead],
		a.[MsgReplied],
		a.[MsgNew],
		a.[ReplyOfMessageID],
		a.[InitialMessageID]
    FROM
		[tbl_Messages] a
	INNER JOIN
		[tbl_Profile] b
		ON
			a.[ProfileID]=b.[ProfileID]
    WHERE
		a.[FromProfileID] =@FromProfileID AND
		a.[MsgNew]=0
    ORDER BY
		a.[MsgDate] DESC
END
GO
Random Solutions  
 
programming4us programming4us