Tag: sql-server

Import multiple delimited text files into a SQL Server database and automatically create tables

I have multiple delimited text files (e.g. .csv files), each containing columns, rows and a header. I want to import all of these input files into SQL Server with as much ease as possible. Specifically, I want to create the output tables into which I will import these files on the fly. Some of these […]

select other column which having min value in subquery

Is there any way to select other column which having MIN value in subquery? In my subquery, i produce lists of value. Then how to get the time that I produce that value here is my code : Select A, (select Time from result where value = ??MIN VALUE), MIN (value) from ( //subquery ) […]

How to export selective columns of multiple tables from SQL Server to one csv file?

In SQL Server (or SQL Server Data Tools) is there a way to export selective columns of multiple tables from SQL Server to one csv file? The database is a Linked Server object connected in SQL Server connected ODBC.

Is there a way to retrieve inserted identity as well as some values from the query in an INSERT SELECT?

I have a situation in which I need to insert some values from a query into a table that has an identity PK. For some of the records, I need also to insert values in another table which has a 1-to-1 (partial) relationship: CREATE TABLE A ( Id int identity primary key clustered, Somevalue varchar(100), […]

how to substring an empty phrase in sql?

I have a link and I want to substring it into many pieces to get numbers example:- &OR=-12&MR=24560&MM=20&Mx=110&EOW=1&OW=50&OV=12&CV=-1 I want the -12 , 24560 , 20 , … etc. and I did it using this code DECLARE @strprog AS NVARCHAR(MAX)–,@strLM AS NVARCHAR(20),@strLOW AS NVARCHAR(20),@strLOR AS NVARCHAR(20),@strLCR AS NVARCHAR(20), DECLARE @OR AS SMALLINT, @MR AS SMALLINT, […]

Aggregate function with image data type

What is the best way to perform an aggregate function on an image data type? For example, where binImage is image data type, and I want to return either binImage or null: max( case when somechar = ‘A’ and anotherchar = ‘B’ then binImage else null end ) as result … will not work, because […]

Seeding my DB with Entity Framework DateTimes

I am using Code First Workflow with Entity Framework 6.1.3 and I am trying to seed my database with some data by adding a migration like so: public partial class SeedDatabaseWithBusinesses : DbMigration { public override void Up() { Sql(“INSERT INTO Businesses (GooglePlaceId, Name, CurrentMenu, LastUpdated)” + ” VALUES (‘googlePlaceIdHere’, ‘Examples Businesses Name’, ‘Fish and […]

Add “- All” as default parameter in my SSRS binary parameter

I have some parameter in a SSRS. I add a “- All” parameter as default value in all of them. For one parameter, a binary one, this cause this error : Syntax error converting the nvarchar value ‘- All’ to a column of data type bit. Here is my Query : SELECT mValue.value AS V […]

Improving performance of wildcard date pattern searchs

I have a wildcard search that I need to improve performance: mycolumn like ‘%-%%-%’ There is a way to do that? (for exemple, with Full-Text Index?) Obs: I have to find dates in my text that follows the pattern, like 21-07-2016. EDIT I have a legacy database that I cannot change the structure. So, I […]

Query Subquery Results in SQL

I am relatively new to SQL and I may be over thinking it but given the following table.I want a list of all students that are enrolled in Chemistry but not Mathematics.So given the data I would have Student 1. Student_ID Subject 1 Chemistry 2 Mathematics 2 Chemistry 3 History Here’s what I tried SELECT […]

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