Click here to Skip to main content
15,890,186 members
Home / Discussions / Database
   

Database

 
AnswerRe: Sql Pin
Paul Conrad17-Oct-08 6:38
professionalPaul Conrad17-Oct-08 6:38 
AnswerRe: Sql Pin
Wendelius19-Oct-08 0:12
mentorWendelius19-Oct-08 0:12 
QuestionSET NOCOUNT ON; Pin
geekfromindia17-Oct-08 5:09
geekfromindia17-Oct-08 5:09 
AnswerRe: SET NOCOUNT ON; Pin
Jon_Boy17-Oct-08 10:19
Jon_Boy17-Oct-08 10:19 
GeneralRe: SET NOCOUNT ON; Pin
geekfromindia17-Oct-08 12:01
geekfromindia17-Oct-08 12:01 
GeneralRe: SET NOCOUNT ON; Pin
Jon_Boy17-Oct-08 13:23
Jon_Boy17-Oct-08 13:23 
AnswerRe: SET NOCOUNT ON; Pin
Mycroft Holmes17-Oct-08 22:57
professionalMycroft Holmes17-Oct-08 22:57 
QuestionProblem with creating a table using a stored procedure [modified] Pin
TheComputerMan17-Oct-08 4:29
TheComputerMan17-Oct-08 4:29 
Hi, I searched the boards and found how to do this, but I have come up against a problem that I cannot seem to resolve.

This is the code to create the stored procedure: (It was create first but I have been playing with it)

ALTER PROCEDURE [dbo].[sproc_CreateMarriageTable] 
	-- Add the parameters for the stored procedure here
	@Surname varchar(50) 
AS
BEGIN
	DECLARE @SQLStatement varchar(1500)
	SET @SQLStatement = 'CREATE TABLE [' + @Surname + ']
	([AutoID] [int] IDENTITY(1,1) NOT NULL,[FirstName] [nvarchar](50) NULL CONSTRAINT [DF_' + @Surname +'_FName]  DEFAULT (''''), 
	[SecondName] [nvarchar](50) NULL CONSTRAINT [DF_' + @Surname + '_SName]  DEFAULT (''''), 
	[ThirdName] [nvarchar](50) NULL CONSTRAINT [DF_' + @Surname + '_TName]  DEFAULT (''''), 
	[MF] [nvarchar](1) NOT NULL CONSTRAINT [DF_' + @Surname + '_MF]  DEFAULT (''M''), 
	[Year] [smallint] NULL CONSTRAINT [DF_' + @Surname + '_Year]  DEFAULT ((0)), 
	[Quarter] [smallint] NULL CONSTRAINT [DF_' + @Surname + '_Qtr]  DEFAULT ((1)), 
	[PersonMarried] [nvarchar](50) NULL CONSTRAINT [DF_' + @Surname + '_PerMar]  DEFAULT (''''), 
	[BirthDate] [smalldatetime] NULL, 
	[Volume] [nvarchar](6) NULL CONSTRAINT [DF_' + @Surname + '_Vol]  DEFAULT (''''), 
	[PageNo] [nvarchar](6) NULL CONSTRAINT [DF_' + @Surname + '_PNo]  DEFAULT (''''), 
	[RegDistrictCode] [int] NOT NULL CONSTRAINT [DF_' + @Surname + '_RegDistCode]  DEFAULT ((0)), CONSTRAINT [PK_' +@Surname + '] 
	PRIMARY KEY CLUSTERED ([AutoID] ASC)WITH 
	(PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) 
	ON [PRIMARY]) 
	ON [PRIMARY]'

	EXEC @SQLStatement
END


This parses and compiles without any errors. Then I tried to execute the procedure:

USE [BMD2005]
GO

DECLARE	@return_value int

EXEC	@return_value = [dbo].[sproc_CreateMarriageTable]
		@Surname = N'M_VAISEY'

SELECT	'Return Value' = @return_value

GO


It fails with the message:

Msg 203, Level 16, State 2, Procedure sproc_CreateMarriageTable, Line 29
The name 'CREATE TABLE [M_VAISEY]
([AutoID] [int] IDENTITY(1,1) NOT NULL,[FirstName] [nvarchar](50) NULL CONSTRAINT [DF_M_VAISEY_FName] DEFAULT (''),
[SecondName] [nvarchar](50) NULL CONSTRAINT [DF_M_VAISEY_SName] DEFAULT (''),
[ThirdName] [nvarchar](50) NULL CONSTRAINT [DF_M_VAISEY_TName] DEFAULT (''),
[MF] [nvarchar](1) NOT NULL CONSTRAINT [DF_M_VAISEY_MF] DEFAULT ('M'),
[Year] [smallint] NULL CONSTRAINT [DF_M_VAISEY_Year] DEFAULT ((0)),
[Quarter] [smallint] NULL CONSTRAINT [DF_M_VAISEY_Qtr] DEFAULT ((1)),
[PersonMarried] [nvarchar](50) NULL CONSTRAINT [DF_M_VAISEY_PerMar] DEFAULT (''),
[BirthDate] [smalldatetime] ' is not a valid identifier.

The declaration of the statement variable is plenty long enough (The text is about 1200 characters) and the place where it stops is about 687 characters.

Is there a problem with NULL? Do I need to enclose that in something?

If anyone can see what the problem is I would be most grateful. Big Grin | :-D

DavidConfused | :confused:

UPDATE: I removed a couple of the filds from the end and got this message when I executed

Msg 203, Level 16, State 2, Procedure sproc_CreateMarriageTableTest, Line 25
The name 'CREATE TABLE [M_VAUGHAN]
([AutoID] [int] IDENTITY(1,1) NOT NULL,[FirstName] [nvarchar](50) NULL CONSTRAINT [DF_M_VAUGHAN_FName] DEFAULT (''),
[SecondName] [nvarchar](50) NULL CONSTRAINT [DF_M_VAUGHAN_SName] DEFAULT (''),
[ThirdName] [nvarchar](50) NULL CONSTRAINT [DF_M_VAUGHAN_TName] DEFAULT (''),
[MF] [nvarchar](1) NOT NULL CONSTRAINT [DF_M_VAUGHAN_MF] DEFAULT ('M'),
[Year] [smallint] NULL CONSTRAINT [DF_M_VAUGHAN_Year] DEFAULT ((0)),
[Quarter] [smallint] NULL CONSTRAINT [DF_M_VAUGHAN_Qtr] DEFAULT ((1)),
[BirthDate] [smalldatetime] NULL
PRIMARY KEY CLUSTERED ([AutoID] ASC)WITH
(PAD_INDEX = OFF, STATISTI' is not a valid identifier.

It would seem there is some lenght of string problem. Any ideas?

modified on Friday, October 17, 2008 11:07 AM

AnswerRe: Problem with creating a table using a stored procedure Pin
TheComputerMan17-Oct-08 5:22
TheComputerMan17-Oct-08 5:22 
AnswerRe: Problem with creating a table using a stored procedure Pin
Kevin Horgan23-Oct-08 2:08
Kevin Horgan23-Oct-08 2:08 
GeneralRe: Problem with creating a table using a stored procedure Pin
TheComputerMan23-Oct-08 2:20
TheComputerMan23-Oct-08 2:20 
GeneralRe: Problem with creating a table using a stored procedure Pin
TheComputerMan23-Oct-08 3:35
TheComputerMan23-Oct-08 3:35 
Question'Open Table' menu option missing in SSMS 08 (SQL compact 3.5) Pin
Jon_Boy17-Oct-08 2:44
Jon_Boy17-Oct-08 2:44 
AnswerRe: 'Open Table' menu option missing in SSMS 08 (SQL compact 3.5) Pin
Jon_Boy18-Oct-08 14:41
Jon_Boy18-Oct-08 14:41 
QuestionFind Percentage? Pin
PadmaPriya.S16-Oct-08 23:59
PadmaPriya.S16-Oct-08 23:59 
AnswerRe: Find Percentage? Pin
Ashfield17-Oct-08 0:54
Ashfield17-Oct-08 0:54 
GeneralRe: Find Percentage? Pin
PadmaPriya.S17-Oct-08 1:09
PadmaPriya.S17-Oct-08 1:09 
GeneralRe: Find Percentage? Pin
Ashfield17-Oct-08 1:12
Ashfield17-Oct-08 1:12 
GeneralRe: Find Percentage? Pin
PadmaPriya.S17-Oct-08 1:14
PadmaPriya.S17-Oct-08 1:14 
GeneralRe: Find Percentage? Pin
Ashfield17-Oct-08 1:29
Ashfield17-Oct-08 1:29 
GeneralRe: Find Percentage? Pin
PadmaPriya.S17-Oct-08 1:39
PadmaPriya.S17-Oct-08 1:39 
QuestionIs this possible?? Pin
VinothRao16-Oct-08 20:48
VinothRao16-Oct-08 20:48 
AnswerRe: Is this possible?? Pin
Mycroft Holmes16-Oct-08 21:39
professionalMycroft Holmes16-Oct-08 21:39 
QuestionDistinct Records Pin
jonhbt16-Oct-08 20:43
jonhbt16-Oct-08 20:43 
AnswerRe: Distinct Records Pin
Eslam Afifi16-Oct-08 21:46
Eslam Afifi16-Oct-08 21:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.