tsql

Removing a default value from a Sql Server 2005 table

Hi, I have a tabel in an Sql Server 2005 database. I have the following column IndPL INT DEFAULT 0 NULL I want to change the column to be of the type NVARCHAR but I receive a constraint violation due to the fact that the column has a default value constraint attached to it. I need to find out how to remove a default value constraint...

ROW_NUMBER() VS. DISTINCT

Dear All, I have a problem with ROW_NUMBER() , if i used it with DISTINCT in the following Query I have 2 scenarios: 1- run this query direct : give me for example 400 record as a result 2- uncomment a line which start with [--Uncomment1--] : give me 700 record as a result it duplicated some records not all the records what I want is...

Use database dynamically

This execution it is giving me an error! Any hints of what am I missing? declare @dbname varchar(500) set @dbname='master' Exec (' Use ' + @dbname + ' go create PROCEDURE [dbo].[krijo_database] @dbname nvarchar(2000), @Direktoria varchar(4000) AS BEGIN declare @stringu nvarchar(100) set @stringu = ''CREATE DATABASE '' +...

SQL ENQUIRY In how to Get defined number of records

I have a select statement, retrieve about 1000 record I want to modify it to return only some records defined by @startIndex and @count e.g. : If I said @startIndex=20 and @count=20 the result will be : from the 21th record to 40th I try to make it, but it take the same time as if I retrieve the 1000 record what is the best way to do ...

Restoring dev db from production: Running a set of SQL scripts based on a list stored in a table?

I need to restore a backup from a production database and then automatically reapply SQL scripts (e.g. ALTER TABLE, INSERT, etc) to bring that db schema back to what was under development. There will be lots of scripts, from a handful of different developers. They won't all be in the same directory. My current plan is to list the scri...

floor of one number for a given precise

how do i floor(or round) a number for a given precise? example: 123333.333334567 after run function like floor(123333.333334567,3) i must have 123333.333 i denoted Floor for my functionality! ...

Shape-like query in T-SQL

I would like to write a T-SQL statement, that structures data to be loaded into a Ado.Net DataSet like it was possible with the ADO SHAPE command. Is there something similar in T-SQL? My idea is to select multiple rows from a main table and all related records from a child table. That data would get loaded in to a DataSet and then I wou...

Is there a way to delay compilation of a stored procedure's execution plan?

(At first glance this may look like a duplicate of http://stackoverflow.com/questions/421275 or http://stackoverflow.com/questions/414336, but my actual question is a bit different) Alright, this one's had me stumped for a few hours. My example here is ridiculously abstracted, so I doubt it will be possible to recreate locally, but it p...

Database Projects: Visual Studio 2008 vs 2010

I just installed VS 2010 for the purposes of running someone else's DB project that was created using the 2010. In VS 2008 I was able to right click on a SQL file ans select "Run ON" to run the script on a given SQL Server. I don't see this option in 2010. Is it available and if so how do I get access to it? ...

Problem counting item frequency on T-SQL

I'm trying to count the frequency of numbers from 1 to 100 on different fields of a table. Let's say I have the table "Results" with the following data: LottoId Winner Second Third ...

Why might SQL execute more quickly on SQL Server 2000 when NOT using a stored procedure?

I could see nothing wrong with the execution plan. Besides, as I understand it, SQL Server 2000 extended many of the performance benefits of stored procedures to all SQL statements by recognising new T-SQL statements against T-SQL statements of existing execution plans (by retaining execution plans for all SQL statements in the procedure...

Is this query safe in SQL Server?

I have this SQL update query: UPDATE table1 SET table1.field1 = 1 WHERE table1.id NOT IN (SELECT table2.table1id FROM table2); Other portions of the application can add records to table2 which use the field table1id to reference table1. The goal here is to remove records from table1 which aren't referenced by table2. Does SQL Serv...

What are maintenance steps and performance steps for Mysql server/database ?

Like index maintenance we have index reorganize/rebuild, update stats, shrink database log files , database backup/restore in MS SQL server, What are maintenance steps and performance steps for Mysql server/database ? ...

How many maximum recursion possible for CTE in SQL server?

How many maximum recursion level possible for CTE in SQL server? If maximum recursion level is reached then what are the alternative way? ...

transforming binary data using ssis and sql server 2008

Hello All - I have a task to import/transform and extract zipped binary files that contain both text data as well as embedded binary data. Within the data is data that is relational in nature and needs to be processed into a defined database structure. Currently I have a C# single threaded app that essentially grabs all the files from th...

Why does concatenating strings in the argument of EXEC sometimes cause a syntax error in T-SQL?

In MS SQL Server Management Studio 2005, running this code EXEC('SELECT * FROM employees WHERE employeeID = ' + CAST(3 AS VARCHAR)) gives this error: Incorrect syntax near 'CAST' However, if I do this, it works: DECLARE @temp VARCHAR(4000) SET @temp = 'SELECT * FROM employees WHERE employeeID = ' + CAST(3 AS VARCHAR) EXEC(@temp) I...

sql server optional parameters: syntax for between clause

@FromDate datetime = null @ToDate datetime = null SELECT * FROM TABLE WHERE .... AND [PI].Date BETWEEN @FromDate AND @ToDate When any date is null, the records are not displayed. What is the correct syntax so that I can get all records if any of the dates are null. I have thought of this: @FromDate datetime = '01/01/1901', @ToDate d...

Performance problem on a query.

Hi, I have a performance problem on a query. First table is a Customer table which has millions records in it. Customer table has a column of email address and some other information about customer. Second table is a CommunicationInfo table which contains just Email addresses. And What I want in here is; how many times the email ad...

Need help limiting a join in Transact-sql

I'm somewhat new to SQL and need help with query syntax. My issue involves 2 tables within a larger multi-table join under Transact-SQL (MS SQL Server 2000 Query Analyzer) I have ACCOUNTS and LOGINS, which are joined on 2 fields: Site & Subset. Both tables may have multiple rows for each Site/Subset combination. ACCOUNTS: ...

Where clause on joined table used for user defined key/value pairs

Our application allows administrators to add “User Properties” in order for them to be able to tailor the system to match their own HR systems. For example, if your company has departments, you can define “Departments” in the Properties table and then add values that correspond to “Departments” such as “Jewelry”, “Electronics” etc… You...