SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[forums_system_Import_User]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[forums_system_Import_User]
GO




CREATE PROCEDURE forums_system_Import_User
	@UserID [int],
	@Password [nvarchar](64) = '',
	@Email [nvarchar](128) = '',
	@DateCreated [datetime],
	@UserName [nvarchar](64) = '',
	@AccountStatus [smallint] = 1,
	@TimeZone [int] = 0,
	@EnableAvatar [smallint] = 0,
	@EnableDisplayInMemberList [smallint] = 1,
	@StringNameValuePairs [varbinary](7500) = 0,
	@EnableThreadTracking [smallint] = 0


AS
BEGIN

	-- Are we creating a user? 
	IF EXISTS(SELECT * FROM forums_Users WHERE UserID = @UserID)
		RETURN
	ELSE
	BEGIN

			SET IDENTITY_INSERT forums_Users ON
			INSERT INTO 
				forums_Users 
				(
					UserID,
					UserName, 
					Email, 
					Password, 
					UserAccountStatus,
					DateCreated
				)
			VALUES	
				(
					@UserID,
					@UserName, 
					@Email, 
					@Password, 
					@AccountStatus,
					@DateCreated
				)
			SET IDENTITY_INSERT forums_Users OFF

			INSERT INTO
				forums_UserProfile
				(
					UserID,
					TimeZone,
					EnableAvatar,
					EnableDisplayInMemberList,
					StringNameValues,	
					EnableThreadTracking,
					ModerationLevel
				)
			VALUES
				(
					@UserID,
					@TimeZone,
					@EnableAvatar,
					@EnableDisplayInMemberList,
					@StringNameValuePairs,
					@EnableThreadTracking,
					1
				)
	END

END

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

