sql-server

How to Change from Sql Server Windows mode to Mixed Mode(SQL SERVER 2008)

hi, I have installed Sql Server 2008 express edition but by mistake I kept the windows authentication mode. Now I want to change that to SQL SERVER MIXED mode. How to do this? Edit: After getting the answer from Jason Punyon & Svetlozar Angelov, I checked Server Authentication under security tab where I found that the Default value se...

SSIS in sql server 2005

I've created a SSIS package, in which I'm calling 2 sp's with a single parameter each. So how to call this package inside a stored procedure by passing a value to as parameter to that package and stored procedure dynamically. ...

Connecting to SQL Server Analysis with a windows user

How can you impersonate a windows user in a connection to an analysis server - using ADOMD.NET? Webserver is next to Analysis server, but they are not in a domain. The webservice running on the webserver needs to access the analysis server as a specific windows account. Is there something I can put in the connection string, or do I ne...

What is the best way to create and populate a numbers table?

I've seen many different ways to create and populate a numbers table. However, what is the best way to create and populate one? With "best" being defined from most to least important: Table created with optimal indexing rows generated fastest simple code used to create and populate If you don't know what a numbers table is, look he...

How do i check all Queries for Binding errors

Hello! I'm in the process to migrate a datebase. New is that a part of the data's home is in an external database (ERP-System). I have to modify a large number of queries. How can i check all queries & SP's, if they still run successfuly? If i have a query 'A' which depends on query 'B', and i change a column in query 'B' i do not get...

Selecting one row from duplicated rows

I have a loooooong stored procedure that runs about 15 select statements across different tables in a database - I am inserting all the results of the selects into a temporary table. However - that table has some rows that are exact duplicates. The temporary table looks something like this: DocID | VisitDate | DocName 824...

Getting an average from subquery values or another aggregate function in SQL Server

I have the SQL statement (SQL Server ) SELECT COUNT(ActionName) AS pageCount FROM tbl_22_Benchmark WHERE DATEPART(dw,CreationDate)>1 AND DATEPART(dw,CreationDate)<7 GROUP BY dateadd(dd,0, datediff(dd,0,CreationDate)) which produces the output pageCount 27 19 59 Now I would like to get the average of all those figures using SQ...

How do I stop MSSQL truncating text when accessed from php?

When I try to retrieve the contents of a Text field from mssql in php I only get back part of the contents. I think its about the first 4000 characters. How do I stop this. ...

Enable sys, guest and information_schema users in SQL Server

I had a script run against one of my databases that attempted to drop a bunch of users. All the users that had the drop attempted against them were disabled and displayed the little red down arrow on their icon in Management Studio. I was able to revive all of the normal users by issuing the "alter login myLogin enable" command. Howev...

Which is better: Bookmark/Key Lookup or Index Scan

I know that an index seek is better than an index scan, but which is preferable in SQL Server explain plans: Index seek or Key Lookup (Bookmark in SQL Server 2000)? Please tell me they didn't change the name again for SQL Server 2008... ...

Best practice on users/roles on SQL Server for a web application

I searched online a bit and couldn't find anything that really nailed the spot or covered the bases how to go about setting up users/roles on a database. Basically, there would be a user that would be used to access the database from the application (web application in this case) that will need access to database for the regular databas...

Return temp table of continuous dates

I need to create a function that returns a table of continuous dates. I would pass in a min & max date. I expect it to be able to be called like this: SELECT * FROM GetDates('01/01/2009', '12/31/2009') I currently have a stored proc that does this, but requirements changed and now I need to do include the returned data from within a ...

Merge SQL Server databases

I'm attempting to merge multiple SQL Server databases into one. The problem is that one of the tables has an identity field as the primary key. The table also has two uniqueid fields. Something like: datatable: id pk identity link1 uniqueid link2 uniqueid My initial thought was to run the following script: declare @maxId as int set @...

How to determine size property for stored procedure output parameters in C# data access layer

I've made a data access layer modeled shamelessly off of Castle Project's ActiveRecord implementation. In order for it to gain acceptance, it must support the extensive library of stored procedures in use at my organization, which have been written to use every input/output structure imaginable, including return values and output paramet...

Why does 'HASH JOIN' or 'LOOP JOIN' improve this stored proc?

I have a basic query that goes from 6 seconds to 1 second just by changing one join from LEFT JOIN to LEFT HASH JOIN or 'LEFT LOOP JOIN'. Can anyone explain why this would cause such a large increase in performance and why SQL's optimizer isn't figuring it out on it's own? Here is roughly what the SQL looks like: SELECT a.[ID] FROM...

SQL statement to insert record into table that has identity column?

Hello SO: I am attempting to insert a row manually into my SQL Server data table. This table has 5 columns, one identity and four data columns. I looked at this post, but when I run the selected answer's query (after replacing 'GroupTable' with my table name of course), my SQL Server 2005 management studio crashes. I have tried variati...

Best way to calculate Max/Min of N columns in SQL Server

Ok, firstly I've seen this thread. But none of the solutions are very satisfactory. The nominated answer looks like NULLs would break it, and the highest-rated answer looks nasty to maintain. So I was wondering about something like the following : CREATE FUNCTION GetMaxDates ( @dte1 datetime, @dte2 datetime, @dte3 datetime, ...

Indexing Speed in SQL

Hi, When creating indexes for an SQL table,if i had an index on 2 columns in the table and i changed the index to be on 4 columns in the table, what would be a reasonable increase the time taken to save say 1 million rows to expect? I know that the answer to this question will vary depending on a lot of factors, such as foreign keys, ...

How to flip bit fields in TSQL

I'm trying to flip a bit field in SQL Server using an update query, that is, I want to make all the 0's into 1's and vice versa. What's the most elegant solution? There doesn't seem to be a bitwise NOT operator in TSQL (unless I'm missing something obvious) and I haven't been able to find any other way of performing the update. ...

Can you force a SQL Stored Procedure to take locks in a given order

I have two stored procedures, one of which is called a lot and is thus very simple and executes well. Additionally, these actually work very nicely in paralell even though they are serializable. However I have a second query that is only called in certain circumstances which needs to do many more checks before touching the same tables....