Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Wednesday, February 27, 2019

SQL error {"String or binary data would be truncated.\r\nThe statement has been terminated."}

{"String or binary data would be truncated.\r\nThe statement has been terminated."}

test it out column by column on the SQL management studio, usually the database column size is too small to fit data coming in.

Monday, January 21, 2019

SQL select with timestamp

SELECT ...
FROM ...
WHERE MyDate BETWEEN '2005-07-12 07:00:00' and '2005-07-12 08:00:00'

SELECT TOP (9) [Volume]
      ,[Open]
      ,[High]
      ,[Low]
      ,[Close]
      ,[WAP]
      ,[Count]
      ,[dt]
      ,[EMA9]
      ,[EMA10]
      ,[EMA20]
      ,[EMA21]
      ,[EMA50]
      ,[EMA100]
      ,[EMA200]
  FROM [market_data].[dbo].[NFLX]

  WHERE dt <= '2019-01-18 19:42:00'

Thursday, October 18, 2018

AZure data sync using power shell

https://docs.microsoft.com/en-us/azure/sql-database/scripts/sql-database-sync-data-between-sql-databases

https://blogs.msdn.microsoft.com/datamigration/2018/02/08/automating-the-end-to-end-migration-of-sql-server-to-azure-sql-database-using-the-azure-database-migration-powershell-module/


alter table with primary key


drop index CIX_DT on dbo.[AAPL];

ALTER TABLE dbo.[AAPL] ADD CONSTRAINT [PK_dt] PRIMARY KEY CLUSTERED
(
    dt DESC
)

create table with primary key

The issue with this you have to make sure PK_KEY that KEY has to be unique

USE [market_data]
GO

/****** Object:  Table [dbo].[FLKS]    Script Date: 10/18/2018 6:57:24 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[FLKS](
 [Volume] [numeric](9, 0) NULL,
 [Open] [decimal](18, 4) NULL,
 [High] [decimal](18, 4) NULL,
 [Low] [decimal](18, 4) NULL,
 [Close] [decimal](18, 4) NULL,
 [WAP] [decimal](18, 4) NULL,
 [Count] [numeric](9, 0) NULL,
 [dt] [datetime] NOT NULL,
 [EMA9] [decimal](18, 4) NULL,
 [EMA10] [decimal](18, 4) NULL,
 [EMA20] [decimal](18, 4) NULL,
 [EMA21] [decimal](18, 4) NULL,
 [EMA50] [decimal](18, 4) NULL,
 [EMA100] [decimal](18, 4) NULL,
 [EMA200] [decimal](18, 4) NULL
) ON [PRIMARY]
GO

ALTER TABLE dbo.[FLKS] ADD CONSTRAINT [PK_FLKS] PRIMARY KEY CLUSTERED
(
    dt DESC
)

Monday, May 4, 2015

SQL join

http://www.sql-tutorial.com/sql-join-sql-tutorial/

Wednesday, January 28, 2015

SQL group by

When grouping, keep in mind that all columns that appear in your SELECT column list, that are not aggregated (used along with one of the SQL aggregate functions), have to appear in the GROUP BY clause too.