sql-server

Using SELECT TOP from one column, then sorting on a different column

I'm using SQL Server 2005, and I want to query for the vendors generating the most revenue, sorted by the vendor's name. Below is the query I have tried. The inner subquery gets the 15 largest vendors sorted by revenue, and I try to order those results by the vendor name. SELECT Revenue, VendorName FROM ( SELECT TOP 15 SUM(...

SEARCH several Tables IN SQL

I'm trying to search several tables at once for a search term. My query is: SELECT item.ItemID FROM Inventory.Item item JOIN Inventory.Category catR // each item can be in several categories ON catR.ItemID = item.ItemID JOIN Category.Category cat ON cat.CategoryID = catR.CategoryID ...

SQL Agent not kicking off an SSIS package

I have a server that has a SQL Agent job setup to run a two part datawarehouse build and Analysis Services cube build. The job ran successfully until there was a problem with Management Studio and .NET framework 2.0 SP1 was re-installed. The first step in the SQL Agent job is unable to kick off the SSIS package. If the Agent job is start...

Inserting Randomly Selected Records SQL

I'm using Microsoft SQL Server 2005. I'm creating a random record generator that will insert 10 records randomly into a temporary table. The records in the temporary table will then be used to update records in the table in memory. Here is the statement that is giving me some troubles (assume the temp table is already created). i...

SQL Server add a column constraint to limit data to -1 to 1

Hello, I want to constrain a SQL Server decimal column to only allow -1,0,1 as valid values. Can you show me the SQL syntax for adding such a constraint. (I would like to know how to do it in both the CREATE TABLE statement and/or the ALTER TABLE ADD CONSTRAINT). Or can this only be accomplished in a trigger? Seth ...

What is the Sql Server equivalent for Oracle's DBMS_ASSERT?

DBMS_ASSERT is one of the keys to prevent SQL injection attacks in Oracle. I tried a cursory search...is there any SQL Server 2005/2008 equivalent for this functionality? I am looking for a specific implementation that has a counterpart of all the respective Oracle package members of DBMS_ASSERT. NOOP SIMPLE_SQL_NAME QUALIFIED_SQL_N...

Creating multiple stored procedures from SQL executed by powershell issue

Ok, so I've got a bit of a SQL and Powershell problem. There are 2 SQL scripts, one to setup 4 different global stored procedures. Another to execute them and manipulate data before returning it to PS to be placed in a CSV file. The reason I'm not putting them into a single file is for readability. The procs are enclosing huge chunks of ...

Scramble a column in SQL Server?

We have a web app we'd like to demo to prospects, but our best way of doing so is with existing data, for a full experience. Certainly, we don't want to do this with actual customer names or addresses, etc visible in the app. Is there an easy way in SQL Server to randomize or scramble a varchar or text field? None of these columns are...

Cannot shrink transaction log,no matter what I do.

I have a database whose tlog has grown to 4.5 GB. The db is in full recovery mode and I have tried several transaction log backups coupled with DBCC shrinkfile. And it will not shrink. Does anyone have any ideas? There are several transactions which have a status =2, but there are no active transactions in the database. I wonder why the...

SQL Server 2008 can't login with newly created user

Using Vista... 1) I open SQL Server Management Studio. 2) I create a new Login by right-clicking on Security->Logins. Check: SQL Server Authentication Login name: tester Password: test Click OK 3) Click File -> Connect Object Explorer, select SQL Server Authentication and enter tester/test and click Connect. 4) Get "Login failed for u...

SQL 2005 Database diagram support objects cannot be installed because this database does not have a valid owner

I have two databases, production and stage. I am getting the error message in the title of this post when I click "Database Diagrams" for production, but on stage I don't get an error. I've researched this message, and I've found posts such as this: http://geekswithblogs.net/shahed/archive/2007/11/19/116940.aspx They pretty much say to...

Find out the values between a range in SQL Server 2005(SET BASED APPROACH)?

I have a table like Id Value 1 Start 2 Normal 3 End 4 Normal 5 Start 6 Normal 7 Normal 8 End 9 Normal I have to bring the output like id Value 1 Start 2 Normal 3 End 5 Start 6 Normal 7 Normal 8 End i.e. the records between Start & End. Records with id's 4 & 9 are outside the Start & End henceforth...

SQL Server pooling Issue

Hi Friends I have written a web application in which I have not allowed connection pooling for this application. I have written sample code as shown below which gets record from my table 20 times and fill in Data set I have close connection at every time. But if I look in SQL Server Activity monitor it shows me one connection open in ...

communicate between Firefox extension and .NET application

I am looking for a better way to pass information between my Firefox extension and .NET application. Currently, I am using text files to pass information one way to the .NET application by using the FileSystemWatcher class. The .NET application watches for new files in a specific directory when the Firefox extension writes to it and th...

How to change the sharepoint Configuration on sqlserver namedInstance to default Instance??

Hi I have installed sqlserver as namedinstance first .say(sqlnamed).later i have installed sharepoint and configured named instance as database server for sharepoint Now i have installed sqldefault instance. Now How to configure the sharepoint server to use default instance instead of namedinstance. What is the Procedure i ...

categorize image and video files as albums

I want to categorize image and video files as albums .My application is developed in asp.net and sql2005.Now i am uploading the image s and videos .My aim is to the user can create an album and he should upload files to that album .There have any way to do this?I am using to show the files that uploaded in repeater as links that are popu...

user in database are not login after restoring the database

When i restored database from one server to other server the user's are not login in database but its shown in database then i delete it and make it again through sql/server/security/login and then its work. is someone tell me how can i restore database and do not define user every time... ...

How to drop a list of SQL Server tables, ignoring constraints?

I have a list of half a dozen MSSQL 2008 tables that I would like to remove at once from my database. The data has been entirely migrated to new tables. There is no reference in the new tables to the old tables. The problem being that old tables comes with loads of inner FK constraints that have been autogenerated by a tool (aspnet_regs...

Server Or Database

Hi guys I need your opinion.I am in a situation where I need to use ajax so I need to query users info every 30 seconds.....which is more efficient query the server first(say check a text file first) and if there is an update for a user info, do a full blown database query or just directly query the database directly every 30 seconds.Ple...

Before trigger in SQL Server

I have 2 tables: survey (id(PK), name) and survey_to_topic (survey_id(PK,FK,not null), topic_id(PK,FK,not null)). When I try to delete from survey table, I get exception: "The DELETE statement conflicted with the REFERENCE constraint "FK_survey _to _topic _survey". The conflict occurred in database "mydatabase", table "dbo...