tagged [sql]

How to create a table from select query result in SQL Server 2008

How to create a table from select query result in SQL Server 2008 I want to create a table from select query result in SQL Server, I tried but I got an error > Incorrect syntax near the keyword 'AS'

22 May at 05:5

Declare Variable for a Query String

Declare Variable for a Query String I was wondering if there was a way to do this in MS SQL Server 2005: ``` DECLARE @theDate varchar(60) SET @theDate = '''2010-01-01'' AND ''2010-08-31 23:59:59''' ...

Insert all values of a table into another table in SQL

Insert all values of a table into another table in SQL I am trying to insert all values of one table into another. But the insert statement accepts values, but i would like it to accept a select * fro...

23 Feb at 03:27

Split function equivalent in T-SQL?

Split function equivalent in T-SQL? I’m looking to split '1,2,3,4,5,6,7,8,9,10,11,12,13,14,15...' (comma delimited) into a table or table variable. Does anyone have a function that returns each one i...

30 Jan at 15:39

Compare DATETIME and DATE ignoring time portion

Compare DATETIME and DATE ignoring time portion I have two tables where column `[date]` is type of `DATETIME2(0)`. I have to compare two records only by theirs Date parts (day+month+year), discarding ...

SQL query for getting data for last 3 months

SQL query for getting data for last 3 months How can you get today's date and convert it to `01/mm /yyyy` format and get data from the table with delivery month 3 months ago? Table already contains de...

How to change a table name using an SQL query?

How to change a table name using an SQL query? How can I in change the table name using a query statement? I used the following syntax but I couldn't find the rename keyword in SQL server 2005.

24 Jan at 10:6

Resolve hostnames with t-sql

Resolve hostnames with t-sql How can i resolve a hostname in t-sql? a 2000 compatible method is preferred. Although something that works on 2005/2008 would also be helpful. eg. If i have the hostname...

9 Jun at 00:39

SQL Query to add a new column after an existing column in SQL Server 2005

SQL Query to add a new column after an existing column in SQL Server 2005 I need a SQL query which add a new column after an existing column, so the column will be added in a specific order. Please su...

25 Jul at 13:17

How to Alter a table for Identity Specification is identity SQL Server

How to Alter a table for Identity Specification is identity SQL Server --- not working Check Image I have a table ProductInProduct is want its id should be Unique.. ![enter image description here](htt...

25 Jun at 07:37

is not a recognized built-in function name

is not a recognized built-in function name Created a function When

SQL Query - how do filter by null or not null

SQL Query - how do filter by null or not null I want to filter a record.... If statusid is null, filter the record (where statusId is not null) If statusid is not null, filter the record where statusi...

Time part of a DateTime Field in SQL

Time part of a DateTime Field in SQL How would I be able to extract the time part of a DateTime field in SQL? For my project I have to return data that has a timestamp of 5pm of a DateTime field no ma...

How to use the divide function in the query?

How to use the divide function in the query? I want to show the percentage for the Overshipment column. My sample query Table Name - CSPGI09_OVERSHIPMENT My formula: ``` ------------------------------...

Refresh Application Automatically When Data changed in SQL Server

Refresh Application Automatically When Data changed in SQL Server I use SQL Server and I have 3 Application servers. When a table in my database have changed I need to those application servers refres...

How do I see active SQL Server connections?

How do I see active SQL Server connections? I am using SQL Server 2008 Enterprise. I want to see any active SQL Server connections, and the related information of all the connections, like from which ...

21 Jan at 21:33

How to insert a blob into a database using sql server management studio

How to insert a blob into a database using sql server management studio How can I easily insert a blob into a `varbinary(MAX)` field? As an example: thing I want to insert is: c:\picture.png the table...

19 Mar at 22:20

Get 2 Digit Number For The Month

Get 2 Digit Number For The Month I have an integer column "Month" I would like to get 2 digit number for month. This is what I have tried: DATEPART(mm, @Date) It returns one digit for months January t...

20 Feb at 09:6

How to generate a range of numbers between two numbers?

How to generate a range of numbers between two numbers? I have two numbers as input from the user, like for example `1000` and `1050`. How do I generate the numbers between these two numbers, using a ...

15 Sep at 20:44

Slow (to none) performance on SQL 2005 after attaching SQL 2000 database

Slow (to none) performance on SQL 2005 after attaching SQL 2000 database Issue: Using the detach/attach SQL database from a SQL 2000 SP4 instance to a much beefier SQL 2005 SP2 server. Run reindex, re...

Are there any disadvantages to always using nvarchar(MAX)?

Are there any disadvantages to always using nvarchar(MAX)? In SQL Server 2005, are there any disadvantages to making all character fields nvarchar(MAX) rather than specifying a length explicitly, e.g....

3 Feb at 13:5

Convert Month Number to Month Name Function in SQL

Convert Month Number to Month Name Function in SQL I have months stored in SQL Server as 1,2,3,4,...12. I would like to display them as January,February etc. Is there a function in SQL Server like Mon...

23 May at 14:9

Select statement to find duplicates on certain fields

Select statement to find duplicates on certain fields Can you help me with SQL statements to find duplicates on multiple fields? For example, in pseudo code: and from the above statement I would like ...

3 Sep at 09:40

SQL Server 2008: how do I grant privileges to a username?

SQL Server 2008: how do I grant privileges to a username? I need to be able to establish an ODBC connection through SQL Server authentication. In SSMS how do I grant permission for a user to be able t...

22 Oct at 16:3

SQL Query - Concatenating Results into One String

SQL Query - Concatenating Results into One String I have a sql function that includes this code: I need to concatenate all results from the select query into CodeNameString. Obviously a FOREACH loop i...

4 Mar at 16:22