Tag: sql

How to remove duplicate accounts in SQL?

I am using SQL Server 2008 and I was wondering how to remove duplicate customers either from the table or exclude it in my query. An Account_ID can only have 1 product associated with it. And the account with the most recent purchase date is what should be showing. An example is below: Account_ID, Account_Purchase, […]

How to create an increment table on execution

I want to know how to create an increment table, so that when a procedure is executed, the table contains the same number of rows as the parameter used to execute the procedure. For example if I perform this: EXEC PROCEDURE [dbo].[insert_number] 5 I should have a table (let’s call the table ‘Number’) that displays […]

How to skip last row using BULK INSERT?

Is it possible to skip last row using BULK INSERT? If not, is there a way I could pre-process text file using windows command line? Thanks!

Attach DataBase Syntax Error

I am trying to attach a DB and can’t figure out the syntax. DECLARE @path1 varchar(250)=N’D:\MSSQL\DATA\ProductDB_Temp.mdf’; DECLARE @path2 varchar(250)=N’D:\MSSQL\DATA\ProductDB_Temp_log.ldf’; /* Attach Database */ CREATE DATABASE ProductDB_Temp ON ( FILENAME = @path1 ) , ( FILENAME = @path2 ) FOR ATTACH Error message: Incorrect syntax near ‘@path1’. Expecting ID,Integer,Quoted_Id,string or text_lex if I construct my script […]

Sql getting two rows from second table in one statement

I have two tables: Order Table ID OrderDate Employee Manager 1 1/1/2016 100 101 2 1/2/2016 100 101 3 1/2/2016 100 4 1/2/2016 101 Employee Table Eid Name 100 Matt 101 Bill I need the result like this 1/1/2016 Matt Bill 1/2/2016 Matt Bill 1/2/2016 Matt 1/2/2016 Bill My SQL Select O.* from Orders JOIN […]

What are the drawbacks of having million+ tables in same DB?

I have designed a DB that will create tables dynamically and load data into it. (single user’s data is stored in single table) So now my DB is having around million+ tables with 2% having millions of rows in it and 30% having nearly a million of records and 68% having 1000-10,000 rows in each […]

How to connect to an Oracle db using a stored procedures within a Microsoft SQL server?

I need to verify data between and Oracle db and a Microsoft SQL server db to verify that if there differences between the two and then update the Microsoft SQL server with any changes there may be

SQL Server : GROUP CONCAT with DISTINCT is sorting natural data input

I have a similar situation. I start out with a table that has data input into a column from another source. This data is comma delimited coming in. I need to manipulate the data to remove a section at the end of each. So I split the data and remove the end with the code […]

SQL foreign key constraint with additional column value check

I have this situation CREATE TABLE [dbo].[Customer] ( Id INT IDENTITY(1,1) NOT NULL, IsWholesaler BIT NOT NULL, Name NVARCHAR(255) NOT NULL ) CREATE TABLE [dbo].[WholesalerUser] ( Id INT IDENTITY(1,1) NOT NULL, CustomerId INT NOT NULL, UserId INT NOT NULL ) CREATE TABLE [dbo].[User] ( Id INT IDENTITY(1,1) NOT NULL, Name NVARCHAR(255) ) One Customer which […]

How to find candian postal code between low and High by SQL Server or c#

I just want to know how to find Canada or UK postal between low and High Postal code. For Example: Low postal code: A0A0A0 and High is: A0Z9Z9 How to find postal code between these postal A0A0A0 and A0Z9Z9?

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.