sql-server

SQL Join on Nearest less than date.

Normally I would just do this in the code itself, but I am curious if this can be accomplished efficiently in TSQL. Table 1 Date - Value Table 2 Date - Discount Table 1 contains entries for each day. Table 2 contains entries only when the discount changes. A discount applied to a value is considered valid until a new discount is en...

Global variables in SQL

Let's say I wanted to create a sql script and do something like this: DECLARE @SomeVariable int SET @SomeVariable = 'VALUE' FROM someTable --do stuff with @SomeVariable GO CREATE PROCEDURE myProcedure ( @MyParameter ) AS SET NOCOUNT ON --Do something --Do something using @SomeVariable SET NOCOUNT OFF RETURN 0 GO I can't, because...

TSQL: Create a view that accesses multiple databases

I have a special case, for example in table ta in database A, it stores all the products I buy table ta( id, name, price ) in table tb in database B, it contain all the product that people can buy table tb( id, name, price .... ) Can I create a view in database A to list all the products that I haven`t bought? ...

How to optimize or remove redundancy from following query

I have 4 tables Table1 (employee) id name -------------------- 1 a 2 b Table2 (appointment) id table1id table3id table4id sdate edate typeid ----------------------------------------------------------------------------------- 1 1 1 1 1/1/09 NULL 100...

SQL Server insert statement

In a database insert statement that could potentially insert more than one row, if there is an error in 1 row (of many), how will i know what the exact error is - which row and which column? Any ideas? ...

Ensure that text field in Sql Server database uses specific font

Short Background: I finally isolated a bug I'm having. The problem is web users of mine who are accessing my ASP.NET application using Safari are storing their content in a different font than all other users. This is a problem because the 3rd party application I am using to dynamically create PDF's only recognizes 2 fonts (arial and tim...

How to reverse the sp_hidetext command?

It appears that it can't be done, but I really don't know why. When Sql Server executes an stored procedure it needs it's code to run it, so I'm sure that the stored procedure's code must exists in some place, but I don't know where, either. Maybe this code is encrypted, but it could be decrypted with some tool, since the DBMS needs to ...

[TSQL] how to write a efficient to get the difference from two table

hi i am using SQL Server 2008, want to create a view to list the different between two tables. for example t1 id name ---- ------ 1 John 2 peter 3 mary 4 joe 5 sun t2 id name --- ---- 1 john 2 joe how to create a view to list all the name in t1 but not in t2. i tried to do that, and alwa...

Reporting Services 2005: Attempt to export to Excel gives "Object reference not set to an instance of an object." error

I have a moderately complex report consisting of a lot of subreports. One particular one is causing an issue: if you run it standalone, it works fine. If you integrate it as a subreport, it refuses to allow you to export to Excel format (from Preview), with the following error: An error occurred during local report processing. An erro...

SQL: Create new database options explanation..

When creating a new database in SQL SERVER, there are many options. Can any of you guys please help me in understanding all these options? Any explanation/links/help well appreciated. ...

SQL Server - changing a null string to an empty string in select statment

Hello, I have a SQL Server 2005 table that has a string column in which empty values are sometimes stored as NULL and other times as an empty string. I am doing a SELECT DISTINCT on this column and I am getting all the distinct values + NULL + empty string. But what I would like is to check if the value is NULL and return an empty stri...

How to query from log files (.ldf) of Sql Server 2005 Express edition?

I want to do this, because I would like to know how many times a particular row has been changed. Is this possible? Thanks ...

Calling SQL Server Reporting Services from PHP - authentication problem

We need to use SQL Server Reporting Services in a website with server-side php and php authentication. At the moment we have two separate logins/authentication – the php and the SQL Server Reporting Services one (which I believe uses something similar to ASP.NET authentication). We need to have only the php login and we also need the rep...

Conversion failed when converting the nvarchar value to int

hi friends, Declare @count nvarchar(max) set @count ='select COUNT(*) from '+ @tablename+'' if( @count =0 ) begin print 'fail' end else begin print 'success' end end the @count variable is not getting the value 0. it shows the error as Conversion failed when converting the nvarchar value 'select COUNT(*) from tablename' to dat...

mysql_real_escape_string alternative for SQL Server

Am wondering what is the equivalent in PHP for SQL Server escaping of strings? ...

Is there a C# open-source search app which scales cheaply?

I need to quickly replace a listings website which has the following characteristics: smallish database (10,000 items, < 1GB) < 10% of the items updated/created/removed daily most common activity is searching the whole dataset, returning 1-1000 items traffic peaks at 1m page impressions per day Scaling strategy for the existing app h...

Lost Update Anomaly in Sql Server Update Command

Hi, I am very much confused. I have a transaction in ReadCommitted Isolation level. Among other things I am also updating a counter value in it, something similar to below: Update tblCount set counter = counter + 1 My application is a desktop application and this transaction happens to occur quite frequently and concurrently. We re...

Error importing SSIS package with Konesans File system Watcher task into SQL Server 2008

I am importing SSIS packages to SQL Server 2008 that were originally built for SQL Server 2005. I upgraded them in VS2008 and them imported them. They all import and work except for the one with the Konesans File system Watcher task. I installed in the setup exe for Konesans File system Watcher SQL Server 2008 on my dev pc and the produ...

SQL Query taking forever

Hi, I have this webapplication tool which queries over data and shows it in a grid. Now a lot of people use it so it has to be quite performant. The thing is, I needed to add a couple of extra fields through joins and now it takes forever for the query to run. If I in sql server run the following query: select top 100 * from bam_Pr...

SSAS: Error Viewing Cube in Browser

Hello, When I go to browse a cube I created in SSAS, I am getting this error: TITLE: Microsoft Visual Studio Unable to get the window handle for the 'ActionsAwarePivotTable' control. Windowless ActiveX controls are not supported. Anybody know why and how I can fix this? Thanks. ...