sql-server

How to convert a week (200851) into a date (2008-12-27)?

How could I convert a year-week (eg 0852 or 200852) into a date (eg 2008-12-31 or specifically a week-ending day ie Saturday 2008-12-27 or a week-beginning day ie 2008-12-21) ? Any day of the week-ending will do, Friday, Saturday, Sunday or Monday. ...

Too many columns in single table - is it good normal form?

A normalized table should have less number columns and can have reference fields as much as possible. Is it right approach? Is there any relationship between number of columns and a good normalization process? ...

Oracle and SQL Dataset

Problem: I have to pull data from a SQL Server database and an Oracle database and put it together in one dataset. The problem I have is: The SQL Server query requires an ID that is only found from the return of the Oracle query. What I am wondering is: How can I approach this problem in a way such that performance is not harmed? ...

Does Foreign Key improve query performance?

Suppose I have 2 tables, Products and ProductCategories. Both tables have relationship on CategoryId. And this is the query. select p.ProductId, p.Name, c.CategoryId, c.Name AS Category from Products p inner join ProductCategories c on p.CategoryId = c.CategoryId where c.CategoryId = 1; When I create execution plan, table ProductCateg...

Connect to MS SQL Server from PHP on Linux?

I need to connect to an MS SQL Server database from a PHP script running on a Linux server. I'm looking at using FreeTDS as there is no official MS SQL Server driver for Linux. Is this my best option? Is it ok in a production environment? Are there other options, perhaps ODBC? ...

GRANTing permissions across different databases (schemas)

I'm securing the DB by only allowing interaction with the DB through a series of Sprocs; pretty common fare. I've dug up and modified a script which loops through and assigns the user EXECUTE permission for all non-system SProcs. It works a treat except that I'd ideally like to add it to the Master DB so that I can easily use it for any...

Begin...End blocks in SQL Server: Is this code right?

I just want to verify that I'm not missing something here... so bear with me. I'm rewriting a lot of old stored procedures and keep seeing IF statements formatted similar to this: begin if @someParameter <> 'ThisType' set @someCode = right(cast(@pYear as varchar(6)),2) + 'THIS' end So the Begin...End block just wraps (but doe...

Is anyone using the Service Broker in SQL Server?

Hi all! When I attended a presentation of SQL Server 2008 at Microsoft, they did a quick gallup to see what features we were using. It turned out that in the entire lecture hall, my company was the only one using the Service Broker. This surprised me a lot, as I thought that more people would be using it. My experience with SB is that ...

Size of varbinary field in SQL server 2005

Hi! I am trying to determine the size in bytes of the contents in a varbinary(max) field in sql server 2005, using sql. As I doubt there is native support for this, could it be done using CLR integration? Any ideas would be greatly appreciated. ...

Trim all database fields

Hello, Do you know if there's a quick way in sql server (via transact-sql) that I could trim all the database string fields. ...

Number of sockets available for a JDBC connection at Windows 2003

My team built a Windows Service in Java that connects to a SQL Server 2005 in a Windows 2003 Server, using pure JDBC (no connection pooling) with the JTDS driver. After a while, the method that opens the connections to the database start raising exceptions with the following stack trace: java.net.BindException: Address already in u...

SQL server version 10 is not supported Error

Does anybody know where I can find the SQL Database Publishing Wizard for SQL Server 2008? When I try and run version 1.1 it says that SQL server version 10 is not supported. I found a MSDN article that states there is a SQL Database publishing Wizard for SQL Server 2008 in Visual studio 2008 but I have no idea where to find it. We are...

Starting a new app with database support

Hello, I'm starting a new C# project that uses a database, but I want it all to be version controlled. I'm thinking about a SQL server database (If I make a mdf file, will I be able to use it in a computer without SQL Server installed?) and LINQ to SQL. How do you usually start a project like this? Do you create a .sql file to create th...

How do I make this calculated measure roll up properly in SSAS?

I have a calculated measure in Analysis Services that returns the average daily revenue for a location based on their last three periods. Periods are location defined lengths of time, so one location may close their periods monthly, and another may close their periods quarterly. To return the average daily revenue I have a factPeriods ...

How to implement NOT LIKE as the search condition for containstable(Full-Text Query)?

What would be the search condition for the query below if we wanted to retrieve all the keys for which the columnName does not contain "thisWord" ? SELECT [key] AS someValue FROM CONTAINSTABLE ( table ,columnName, ??what goes here?? ) Note: This is a full-text based search. ...

Are SQL stored procedures case sensitive?

for example... ALTER PROCEDURE [dbo].[Reports_Dashboard_Get_Sav] -- Add the parameters for the stored procedure here @startDate datetime, @endDate datetime, @companyID int=null set @days=datediff(m,@startdate,@enddate) if (@days)=0 set @days=1 This is not my code but if this is case sensitive then @days is not...

Multi-tenancy with SQL/WCF/Silverlight

We're building a Silverlight application which will be offered as SaaS. The end product is a Silverlight client that connects to a WCF service. As the number of clients is potentially large, updating needs to be easy, preferably so that all instances can be updated in one go. Not having implemented multi tenancy before, I'm looking for ...

Help with sp_msforeachdb -like queries

Where I'm at we have a software package running on a mainframe system. The mainframe makes a nightly dump into sql server, such that each of our clients has it's own database in the server. There are a few other databases in the server instance as well, plus some older client dbs with no data. We often need to run reports or check da...

Quickest and easiest way to set up a web page to search an SQL database?

I usually only work on system admin projects and software packaging and have little knowledge of web technologies, but I've been given the task of building a simple website that searches an SQL 2005 database from the users input and lists the results. That's it. Can anybody help me out with some sample code or some such? Since we're a p...

SQL Delete Where Not In

Hi I have a relation mapping table like this: attributeid bigint productid bigint To clean relations that are not used any more, I want to delete all recors where productid = x and attributeid not in (@includedIds), like the following example: @attributetypeid bigint, @productid bigint, @includedids varchar(MAX) DELETE FROM relt...