Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm unsure what's wrong when I declare these variables in SQL

I have the following code:

USE pricingdb
go

CREATE TABLE dbo.Events_060107_2012
(
    Date_Time varchar(20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    Event_Type TEXT,
    Month_of_Year TEXT,
    Survey DOUBLE,
    Actual DOUBLE,
    Prior_Data DOUBLE,
    Revised DOUBLE,
    Relevance FLOAT,
    Ticker TEXT
);  

Go

And I'm getting an Error:

"Incorrect syntax near ','.  Level 15, State 1, Line 6"

I'm aware that this should be a pretty easy problem to fix, but for whatever reason I'm having a lot of trouble understanding how to go about fixing this. My knowledge of SQL is beginner at best, so most of the other threads I read were a little above my head.

Thanks in advance for any help.

like image 452
weskpga Avatar asked Jun 05 '12 19:06

weskpga


People also ask

How do you DECLARE a variable in SQL query?

Variables in SQL procedures are defined by using the DECLARE statement. Values can be assigned to variables using the SET statement or the SELECT INTO statement or as a default value when the variable is declared. Literals, expressions, the result of a query, and special register values can be assigned to variables.

Which is the correct way to DECLARE a table variable?

If we want to declare a table variable, we have to start the DECLARE statement which is similar to local variables. The name of the local variable must start with at(@) sign. The TABLE keyword specifies that this variable is a table variable.

Do you have to DECLARE variables in SQL?

Firstly, if we want to use a variable in SQL Server, we have to declare it. The DECLARE statement is used to declare a variable in SQL Server. In the second step, we have to specify the name of the variable. Local variable names have to start with an at (@) sign because this rule is a syntax necessity.


2 Answers

DOUBLE is not a valid datatype in sql server

Use float, numeric, ... or any of the other types that are supported.

More info at http://msdn.microsoft.com/en-us/library/ms187752.aspx

like image 195
buckley Avatar answered Nov 15 '22 21:11

buckley


Two issues. The first is that there is no datatype of double. The second is that float takes a size to indicate the difference in precision. An equivalent create query to the one above is:

CREATE TABLE dbo.Events_060107_2012
(
    Date_Time varchar(20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    Event_Type TEXT,
    Month_of_Year TEXT,
    Survey FLOAT(53),
    Actual FLOAT(53),
    Prior_Data FLOAT(53),
    Revised FLOAT(53),
    Relevance FLOAT(24),
    Ticker TEXT
);
like image 33
Jeff Siver Avatar answered Nov 15 '22 22:11

Jeff Siver