tsql

T-Sql Query - Get Unique Rows Across 2 Columns

I have a set of data, with columns x and y. This set contains rows where, for any 2 given values, A and B, there is a row with A and B in columns x and y respectivly and there will be a second row with B and A in columns x and y respectivly. E.g **Column X** **Column Y** Row 1 A B Row 2 ...

T-SQL "re-runnable" database update scripts - column deletion

For our SQL Server database, we're using a versioning scheme to track schema updates. The idea is that you should be able to run this script to bring the schema from any previous version up to the current version. Running the master script again should only execute the newest schema updates. The structure of the script is like this: ...

To get digits after / in stored procedure

hi guys, I have a field in table.Suppose its value is 2009/1234.I want to get digits before'/'.I want to do this in stored procedure in sql.Can anybody help? ...

SQL Server 2000 gives error on queries that contain more than about 12500 conditions

Hi I have problem with SQL Server 2000 and queries that contain a large number of conditions. When these queries are sent to the SQL Server I get one of the following error messages depending on the query (error messages edited for readability): [Microsoft][ODBC SQL Server Driver][SQL Server] SqlDumpExceptionHandler: Process 61 genera...

file system not supported error while adding a file to sql filegroup with filestream

hi i am a beginner with sql server 2008, i was trying to add a file to a filegroup so that i an create a table which uses filestream, but i keep getting an errors. here is the code that i am trying: ALTER DATABASE dbtry1 ADD FILEGROUP dbtry1_fg_filestream CONTAINS FILESTREAM GO ALTER DATABASE dbtry1 ADD FILE ( NAME= 'dbtry1_files...

Which Join having more I/O and CPU Cyecle ?

Which Join having more I/O and CPU Cycle ? Hash join or Merge join or Loop join? ...

TSQL Pivot without aggregate function

I have a table like this... CustomerID DBColumnName Data -------------------------------------- 1 FirstName Joe 1 MiddleName S 1 LastName Smith 1 Date 12/12/2009 2 FirstName Sam 2 MiddleName S 2 LastName Freddrick 2 ...

Indexed View vs Indexes on Table

I have the following table EVENT_LOG: EVENT_ID: pk, int, not null TYPEID: fk, int, not null CATEGORYID: fk, int, null SOURCE: varchar(255), null DESCRIPTION: varchar(4000), null CREATED: datetime, null We've been creating a report, and found that performance sucks. There aren't any indexes aside from the clustered one. We could cr...

sql server 2000: Short cut for getting stored proc text

Hi, what is the short cut to get entire text of the stored proc in query analyzer. I know that I could highlight table name and hit <alt><f1> and get the entire table structure. ...

How can I drop all indexes in a SQL database with one command?

So, how can I drop all indexes in a SQL database with one command? I have this command that will get me all the 20 or so drop statements, but how can I run all of those drop statements from this "result set"? select * from vw_drop_idnex; Another variation that gives me the same list is: SELECT 'DROP INDEX ' + ix.Name + ' ON ' + OB...

How can I make a stored procedure return a "dataset" using a parameter I pass?

I'm very new to Stored Procedures. Say I have a IDCategory (int) and I pass that to a stored procedure. In normal-talk, it'd go: Find me all the listings with an IDCategory equal to the IDCategory I'm telling you to find. So it would find say 3 listing, and create a table with columns: IDListing, IDCategory, Price, Seller, Im...

TSQL, how to avoid if conditions?

Hello SQL Gurus, I am from procedure programming background, end up writing TSQL recently with my new job. My mindset still thinking about writing queries with if conditions. How to avoid following query without if condition. DECLARE @NumAddress INT SELECT @NumAddress = COUNT(*) FROM Address WHERE UserID = 1001 IF @NumAddress ...

Link one table to another?

i'm trying to set up some tables in my SQL Express server, and i want to do something to the effect of this: create table programs ( progid int primary key identity(1,1), name nvarchar(255), description nvarchar(500), iconFile nvarchar(255), installScript nvarchar(255) ) however i want each "program" to have a set ...

Making a stored procedure return 5 little data from three different tables.

I'm having trouble with stored procedure here and I'm not sure what to do or how to approach this. I'm sure there's a genius out here that can help me out! :D I want my stored procedure to return Anuncio's idAnuncio, titulo, precio, descripcion, and by using it's foreign keys return Categoria's descripcion and Imagenes's imagen. But ...

SQL Query returning repeating information

I'm having an issue where this query statement is giving me repeating GoalText in the results. Any ideas? The complete query statement: Select g.GoalText, convert(nvarchar, g.GoalID) + '|' + convert(nvarchar, r.GoalReqID) as GoalID, GoalReqID from Goal g inner join GoalRequirement r on g.GoalID = r.GoalID where GoalReqID in (Select...

Query Optimization - Why does this speed up the Query?

I'm using Quest's TOAD for SQL Server on a SQL Server 2000 Server. Here is my query: SELECT CASE SLCE.GroupName WHEN 'Other' THEN ARM.FBCOMPANY WHEN 'Inter Co.' THEN ARM.FBCOMPANY ELSE SLCE.GroupName END AS [Company Name], ARM.fcustno AS [Cust No], ARM.fbcompany ...

How to do this query in T-SQL

I have table with 3 columns A B C. I want to select * from this table, but ordered by a specific ordering of column A. In other words, lets' say column A contains "stack", "over", "flow". I want to select * from this table, and order by column A in this specific ordering: "stack", "flow", "over" - which is neither ascending nor descen...

Multivalued parameter within T-SQL Query

I am working on .aspx page that uses a t-sql query that uses a multivalued input parameter (a set of labnames) using an array that would store all the labnames prior to running the query. I have the following parameters for the query. With c.Parameters .Add(New SqlParameter("@sdate", sdate.text)) .Add(New SqlPar...

Select Fails With Nonexisitent Columns

Executing the following statement with SQL Server 2005 (My tests are through SSMS) results in success upon first execution and failure upon subsequent executions. IF OBJECT_ID('tempdb..#test') IS NULL CREATE TABLE #test ( GoodColumn INT ) IF 1 = 0 SELECT BadColumn FROM #test What this means is that something is co...

Is SQL Server 2005 faster when table relationships are defined ?

I heard that SQL is faster if table relationships are defined. Is this true? Or maybe it's slower, I would like to know. ...