sql-server

SQL Hurdle - SQL Server 2008

The following query returns the total amount of orders, per week, for the past 12 months (for a specific customer): SELECT DATEPART(year, orderDate) AS [year], DATEPART(month, orderDate) AS [month], DATEPART(wk, orderDate) AS [week], COUNT(1) AS orderCount FROM dbo.Orders (NOLOCK) WHERE customerNumber = @custnum AND...

Best way to represent a color in a SQL Database?

If I am using .Net and SQL Server 2008, what is the best way for me to store a color in the database, should I use ToString or convert it to an integer, or something else? Edit: All I want from the colour is to be able to retrieve it and draw something on the screen in the specified colour. I don't need to be able to query against it. ...

How can I migrate database from SQL Server 2008 to SQL Server 2000

I am replacing an Access application with a web app, but the client is using SQL Server 2000, and I am using SQL Server 2008. So, I have the database redesigned, with foreign keys, but now I need to get the data on the client's system. Part of the problem is that they have images that are over 32k, so osql failed as the command buffer ...

How to override or workaround compiled DB connection info

I've faced a bit strange problem. There is a site client would like to duplicate on another domain name. Site is built on ASP(yes, old v1 ASP :( ) with SQLServer. Problem is that all the database operations, including connection information is compiled into a DLL library. Is there a way to some how intercept, override or workaround this...

Check constraint on table lookup

Hi, I have a table, department , with several bit fields to indicate department types One is Warehouse (when true, indicate the department is warehouse) And I have another table, ManagersForWarehouses with following structure: ID autoinc WarehouseID int (foreign key reference DepartmentID from departments) ManagerID int (foreign key r...

Saving binary data into SQL SErver database in vb.net

Hello, I have a string with Binarydata that is 64bit. I want to store this data into SQlServer database and the column is varbinary(Max). When I pass the string I am getting an error saying string cannot be converted into varbinary. How do I store the binary data into sql server. Thanks ...

Approximating Page Views Per Tag (or Tag Group) Per Month with Limited Data?

Using the Stack Overflow public data dump, I've created three simple tables: Questions (Question_Id, View_Count, Creation_Date) Tags (Tag_Name) QuestionTags (Question_Id, Tag_Name) The Questions table has hundreds of thousands of rows with Creation_Date spanning from a year ago to today. Looking over the data, there are two notable t...

Fixing Orphaned Users with SQL SMO?

Is there a way to fix an orphaned user in a SQL 2005/2008 database using SQL SMO? You can find orphaned users relatively easily by enumerating through the users and looking for an empty User.Login property: using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Common; public static IList<string> GetOrphaned...

SSRS Header not formatted

Sorry for bad english. We use Sql Server Reporting service (SSRS) and there is a problem with the header (see http://botanix.altitudesolutions.com/problem.png). It seems that this web section is unable to fetch the required CSS. ...

How to increment DateTime field in SQL Server 2005 by a month?

I have a DateTime field in SQL Server for some products expiration (ExpirationDate). I need to increment all the items manually, and set their expiration a month later than the date stored in the field currently. How can I do that? ...

Incorrect syntax near 'E'.

How can I correct the following so that I don't receive a syntax error in Microsoft SQL Server 2005? UPDATE Emp E SET UserName = Left(FirstName,1)+LastName WHERE EmpID=1 AND NOT EXISTS( SELECT * FROM Emp WHERE UserName=Left(E.FirstName,1)+E.LastName ) ...

SQL Server 2005 Pivot Table question

I have an Entity-Value set of tables, and would like to pivot the results. Here's the effect that I'm looking for, except you see that the SELECT stmt using Common Table Expressions isn't working exactly right yet. My question is: Am I on the right track, or is there some sort of easy pivot command? USE TempDB Declare @Person TABLE( Per...

Automating DBCC CHECKDB

I am currently trying to script a job on SQL Server 2005 that will automate the DBCC CHECKDB process. Basically, I am using a cursor to run through and run DBCC CHECKDB on every database on an instance. Sometimes it works, running through every database and logging the errors in a table I have designed for that purpose and sometimes it...

SQL Server 2005 Cursors

what are some of the cases that will cause a SQL Server 2005 cursor to deallocate prematurely? ...

Find GUID in database

I am currently working on a project where some (significant) data corruption has occurred. Specifically the database is using GUIDs as primary keys on most tables, however it is not enforcing data integrity between those tables (due to a long-winded "this was bought from another company and integrated with our stuff" discussion). There...

SQL Server 2005 T-SQL remap columns

I have an application that is ready to go live, once we take data from a MS Access DB and import it into SQL Server 2005. I have used the Migration - Access tool to get the Access db into SQL Server, but now I need to take the data from that table and put it into the tables that our app is going to use. Is there a T-Sql way to Insert m...

How to form the connection string for a SQL Server express instance?

I don't know how to form the connection string. Lets say the server is server.com, with a SQL Instance called MSSQL.1 Looking at a previous example, it looks like the data source would be server.com\MSSQL.1 I installed SQL Express using all the defaults on Windows Server 2003. Any help is appreciated. Thanks Kevin ...

Database Server Disk Memory is Full

I am using SQL Server for my web application. How will I know that an insert query failed because the database server memory disk is already full ...

How can I handle emailed job control files for SQL Server?

How can I detect control files from any mailbox, scan that file, decrypt it and queue it as a job using job manager in SQL Server? ...

Mapping my existing ID column using NHibernate that keeps identity incrementing

I'm learning NHibernate to learn a more robust ORM than linq to sql, but i'm struggling with some simple things. My first challenge is mapping this ID column using hbm.xml. CREATE TABLE [dbo].[Party]( [Id] [int] IDENTITY(1,1) NOT NULL CONSTRAINT [PK_Party] PRIMARY KEY CLUSTERED ( [Id] ASC ) WITH (PAD_INDEX = OFF, STATISTICS_NOREC...