0

I have to use some hardcode data in sql script, for this I am using temp table

CREATE TABLE #Temp
(
    [Type] INT,
    StartDate DATETIME,
    EndDate DATETIME,
    InterestRate DOUBLE
);

INSERT INTO #Temp 
VALUES (1, '2015-07-01', '2017-05-01', 27),
       (1, '2017-05-02', '2017-06-30', 25.71)

On line 6, it is showing error as Expecting Id

Is there any simplest way to do this?

3 Answers 3

1

There is no double data type in sql server use decimal.

CREATE TABLE #Temp
(
    [Type] Int,
    StartDate DateTime,
    EndDate DateTime,
    InterestRate decimal
);

Insert Into #Temp Values 
(1,'2015-07-01','2017-05-01',27),
(1,'2017-05-02','2017-06-30',25.71)
Sign up to request clarification or add additional context in comments.

Comments

0

SQL doesn't support DOUBLE ,you can use float or decimal instead of DOUBLE.

CREATE TABLE #Temp
(
    [Type] Int,
    StartDate DateTime,
    EndDate DateTime,
    InterestRate decimal
);

Insert Into #Temp Values 
(1,'2015-07-01','2017-05-01',27),
(1,'2017-05-02','2017-06-30',25.71)

Comments

0

You should use decimal, but you need to give a scale and precision. The default is 0 . . . which is not so useful for an interest rate. See this example.

CREATE TABLE #Temp (
    [Type] INT,
    StartDate DATETIME,
    EndDate DATETIME,
    InterestRate DECIMAL(10, 6)
);

INSERT INTO #Temp 
    VALUES (1, '2015-07-01', '2017-05-01', 27),
           (1, '2017-05-02', '2017-06-30', 25.71);

In addition, SQL Server does have floating point types. They are called float and real. For financial purposes, I think decimal/numeric is a better choice.

1 Comment

@BlackCat . . . You may want to reconsider your accepted answer, because it does not store the data as you intend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.