SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Create Table Generates Msg 0


Create Table Generates Msg 0

Author
Message
timSF
timSF
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 35
I get this error when creating a table using 'AS CASE WHEN':
Msg 0, Level 11, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.
Msg 0, Level 20, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.

When I remove the line marked below (containing 'AS CASE WHEN'), the table adds fine.


use CompanyData;
go

CREATE TABLE Company
(
companyID int NOT NULL IDENTITY(1,1),
recnum int NOT NULL,
nameFormal nvarchar(100) NOT NULL,
parent nvarchar(100) NULL,
recnumParent int NULL,
sourceRef nvarchar(100) NOT NULL,
comments nvarchar(1000) NULL,
createdBy nvarchar(3) NOT NULL,
createdDate date NOT NULL,
numEmpls int NULL,
emfValidThisCompany char(1) NOT NULL CHECK (emfValidThisCompany IN('Y', 'N')),
nameInternal AS LOWER(nameFormal),
=> nameInternal AS CASE WHEN nameFormal LIKE 'the %' THEN SUBSTRING(nameFormal,1,LEN(nameFormal)-4) ELSE nameFormal END
PRIMARY KEY(companyID)
);

Eugene Elutin
Eugene Elutin
SSCarpal Tunnel
SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)

Group: General Forum Members
Points: 4964 Visits: 5478
you are using invalid sintax. Try:

CREATE TABLE #Company( companyID int NOT NULL IDENTITY(1,1)
, recnum int NOT NULL
, nameFormal nvarchar(100) NOT NULL
, parent nvarchar(100) NULL
, recnumParent int NULL
, sourceRef nvarchar(100) NOT NULL
, comments nvarchar(1000) NULL
, createdBy nvarchar(3) NOT NULL
, createdDate date NOT NULL
, numEmpls int NULL
, emfValidThisCompany char(1) NOT NULL CHECK (emfValidThisCompany IN('Y', 'N'))
, nameInternal AS LOWER(CASE WHEN nameFormal LIKE 'the %' THEN SUBSTRING(nameFormal,1,LEN(nameFormal)-4) ELSE nameFormal END)
PRIMARY KEY(companyID)
);



_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
timSF
timSF
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 35
Thanks very much for your help! What's the # symbol next to the table name mean?
dogramone
dogramone
Right there with Babe
Right there with Babe (743 reputation)Right there with Babe (743 reputation)Right there with Babe (743 reputation)Right there with Babe (743 reputation)Right there with Babe (743 reputation)Right there with Babe (743 reputation)Right there with Babe (743 reputation)Right there with Babe (743 reputation)

Group: General Forum Members
Points: 743 Visits: 3736
All the hash means is the table scope. A has means the table would only be available to the session that created it so its a temporary table.



timSF
timSF
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 35
Got it. Thanks guys for your help.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search