sql-server

How to connect to SQL Server 2008

I have a desktop, and a Laptop. The Desktop has Windows 7 64-bit and the Laptop has Vista Ultimate 32-bit. On both machines I have SQL Server 2008 Standard installed. On the laptop, I open SQL Management Studio and try to connect to the SQL Server on the desktop. It times out. With SQL Server Config Manager I Enabled TCP/IP and Named Pi...

T-SQL, updating more than one variable in a single select

Is it possible to update more than one local variable in a single select? Something like: set @variableOne = avg(someColumn), @variableTwo = avg(otherColumn) from tblTable It seems a bit wasteful to make two separate select operations for something as trivial as this task: set @variableOne = ( select avg(someColumn) from...

Conditional Joins - Dynamic SQL

The DBA here at work is trying to turn my straightforward stored procs into a dynamic sql monstrosity. Admittedly, my stored procedure might not be as fast as they'd like, but I can't help but believe there's an adequate way to do what is basically a conditional join. Here's an example of my stored proc: SELECT * FROM table WHERE ( ...

Best way to parse DateTime to SQL server

I was wondering what is the best way to parse a DateTime object to your SQL server. Where you are generating the SQL in code. I have always used something like DateTime.Now.TolongDateString() and had good results, apart from today where i got a error, and it made me think. System.Data.SqlClient.SqlException: Conversion failed when ...

Using Change Data Capture for Small Desktop Applications?

A new client of mine has a small VB/Access database application written in 2002 that he wants rewritten to bring it more up to date and to support new features he has been wanting for some time. So, I'm going to convert it over to use C#.NET 2008 and SQL Server Express 2008 on the local machine with the ability to scale to using WCF and ...

How do you work with SQL Server CE and SQL Server 2008 Express?

I have installed: Visual C# 2008 Express Visual Web Developer 2008 Express Visual Studio 2008 SQL Server 2008 Express SQL Server Management Studio In Visual C# 2008 Express, I can "Add Item" and create a "Local Database" (.sdf file) or a "Service Based Database" (.mdf file). Visual Studio 2008 is the same as Visual C# 2008 for appl...

Unable to connect to msSQL database via PHP

I am using the current code in attempt to access a msSQL 2005 db: <?php $myServer = "[server]"; $myUser = "[username]"; $myPass = "[password]"; $myDB = "[db]"; //connection to the database $dbhandle = mssql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer"); //select a database to work with $s...

How can I make this query in SQL Server Compact Edition?

Hi, this subquery works in SQL Server: select systemUsers.name, (select count(id) from userIncidences where idUser = systemUsers.id ) from systemUsers How can It be made in SQL Compact? Thanks! ...

How to run SQL Server Management Studio Express from CD

Is it possible to run SQL Server Management Studio Express from CD without installing it on the computer? I need it sometimes to provide support for the client but do not want to install/uninstall it. ...

Ruby on Rails and MSSQL Server: trying to insert rows with newid() default values.

(this question was originally posted in another forum a few months ago, without getting any answer ... there was no SO at these times!) My first steps in RoR. I baught one of these books talking about Ruby, and Ruby On Rails. Examples are running correctly on MySQL, so I decided to rewrite them for MS-SQL as a good exercice (and as MS...

MS SQL to MySQL

How would this stored procedure look like in MySQL? : ========================================================================= Create PROCEDURE [dbo].[Customer_Insert] ( @CustomerID int = NULL OUTPUT, @CustomerRef varchar(25), @Name varchar(64) = NULL, ) AS SET NOCOUNT ON INSERT INTO [Customers] ( [CustomerRef], [Name] ) V...

Database column sizes for character based data

I've just come across a database where all the character based columns have their size specified in multiples of 8 (e.g. Username = varchar(32), Forename = nvarchar(128) etc.) Would this have any bearing on the performance of the database or is it completely pointless? Thanks. N.B. This is in a SQL 2000 database. ...

SQL 2005: Agent job step output file naming

Does anyone know, please, if there's a way to specify "this machine" in a file path that SQL Server will like? I have an Agent job I want to script onto all my servers. It outputs to a file on the local machine so I want to script the file name as \\localhost\<shared-folder-name>\<file-name> Another reason is I'm planning to use log...

DBCC CHECKIDENT Sets Identity to 0

I'm using this code to reset the identity on a table: DBCC CHECKIDENT('TableName', RESEED, 0) This works fine most of the time, with the first insert I do inserting 1 into the Id column. However if I drop the db and recreate it (using scripts I've written) and then call DBCC CHECKIDENT, the first item inserted will have an ID of 0. A...

How do I import an excel spreadsheet into SQL Server?

I need to import an excel spreadsheet into SQL Server 2005. What steps would I need to take to accomplish that? ...

Any SQL Server multiple-recordset stored procedure gotchas?

Context My current project is a large-ish public site (2 million pageviews per day) site running a mixture of asp classic and asp.net with a SQL Server 2005 back-end. We're heavy on reads, with occasional writes and virtually no updates/deletes. Our pages typically concern a single 'master' object with a stack of dependent (detail) obje...

SSRS Security

Scenarion: I am having a web application which is going to use SqlServerReport(SSRS) sitting on ReportingServer which is on my DatabaseServer. There is a firewall between webapplication & SqlserverReport server. Now how safe is it to use reports directly from webserver (ie accessing something there on database server.) We use a appser...

How to group ranged values using SQL Server

I have a table of values like this 978412, 400 978813, 20 978834, 50 981001, 20 As you can see the second number when added to the first is 1 number before the next in the sequence. The last number is not in the range (doesnt follow a direct sequence, as in the next value). What I need is a CTE (yes, ideally) that will output this 97...

Only display the values to the right of a Decimal Number

Hi there, I use SQL Server 2005 and need to test whether values in a column that's metadata has been specified as DECIMAL(18.3) actually contains data that has values to the right of the Decimal point, and if so, what these values are. I've read a few articles that only discuss how to drop off the decimal places or how to round the val...

select statement

what select statement would I use to add the excel spreadsheet to an existing table, as i am getting an error trying to create a new table on the database? please can you assist me. Thanks ...