sql-server

Sql Server - Get view creation statement for existing view

Is there a way to get the statement that created a view for an existing view in SQL Server 2008? I thought there was a stored procedure or some metadata that had this data, but I'm not finding anything. ...

Disbabled sql server job will still try to run at the original scheduled time

I have a sql server job, which has been disabled. But the job continues to attempt to run at the original scheduled time. I wonder why it keeps doing this. Thanks! ...

SQL Server 2000: How to exit a stored procedure?

How can i exit in the middle of a stored procedure? i have a stored procedure where i want to bail out early (while trying to debug it). i've tried calling RETURN and RAISERROR, and the sp keeps on running: CREATE PROCEDURE dbo.Archive_Session @SessionGUID uniqueidentifier AS print 'before raiserror' raiserror('this is a raised error'...

Why is my table-valued parameter empty when reaching the database?

I'm trying to test out the new table-valued parameter functionality of SQL 2008 by calling a stored procedure using ADO.NET, but I'm running into a problem where the parameter seems to contain no rows when it gets to the stored procedure. The UDT looks like this: CREATE TYPE [dbo].[PersonType] AS TABLE( [FirstName] [varchar](50) NULL, ...

Deleting a SQL row ignoring all foreign keys and constraints

I have a row in a table. This row has an ID column referenced in a few other tables with millions of rows. The SQL statement to delete the row always times out. From my design, I know the row I wish to delete is never referenced any where else. Hence I would like SQL to ignore having to check all other tables for a foreign key reference ...

C# using list table and text file to execute SQL query then export

Scenario: I have a list table being populated from a combobox. That list table can have up to 50 things listed in it(whats listed in the listbox is column names). Tricky part: I have a text file that matches one field in the sql table. X1,X2,X3 are the listbox items. So i basically need: select <line in text file>, from <blah> wher...

Best visual modeling tool for SQL Server (Erwin alternative)

We're looking for a visual modeling tool for SQL Server that allows for forward-engineering from the model to DDL. Erwin works great but is unavailable on this project, so we're looking for alternatives, an open source program would be ideal. We also have VSTS Database Edition, but it does not appear to allow for this type of functiona...

sql server 2005 tsql abs doesn't like decimals?

trying to run the following statement in sql mgmt studio declare @rick as decimal(13,3) @rick = -.5 select bob = abs(@rick) any ideas why this won't work? ...

Joining tables based on the maximum value

Here's a simplified example of what I'm talking about: Table: students exam_results _____________ ____________________________________ | id | name | | id | student_id | score | date | |----+------| |----+------------+-------+--------| | 1 | Jim | | 1 | 1 | 73 | 8/1/09 | | 2 | Joe | ...

How do you retrieve the new keys from an INSERT INTO SELECT FROM query?

Is there a way to retrieve all the keys of the newly inserted records when using an INSERT INTO ... SELECT FROM query? ...

Linq-To-SQL Legacy Relation Mapping

Hi, I am trying to get Linq2SQL to work with my legacy database. I currently have a notes table that is generic to a few different entities and mapped m:m. Instead of mapping one relation table per entity type whoever designed this database decided to use a single relation table with a type column (as a varchar yuck!). How do I map F...

Does SQL Server even look at a table when joining on a variable that returns false?

If I join table A to table B like this... select A.* from A left outer join B on A.Id = B.aId and @param = 'someValue' and @param does not equal 'someValue', does SQL Server even attempt to match records from table B or is it smart enough to know the condition will never be true? ...

How do you boost term relevance in Sql Server Full Text Search like you can in Lucene?

I'm doing a typical full text search using containstable using 'ISABOUT(term1,term2,term3)' and although it supports term weighting that's not what I need. I need the ability to boost the relevancy of terms contained in certain portions of text. For example, it is customary for metatags or page title to be weighted differently than bod...

What SQL queries will help analyse a membership base?

At our sports centre, I would like to analyse the number and types of subscriptions our members have, but I'm having trouble with the exact SQL queries. A "subscription" is an entry pass that lets you into specific activities in our sports centre. They have a start and end date, representing the period they are valid. They have an assoc...

Remove trailing empty space in a field content

I am using SQL server MSDE 2000. I have a field called notes of type nvarchar(65). The content is 'Something ' with an extra space after the content (quotes for clarity) in all the records. I used the following command. UPDATE TABLE1 SET notes = RTRIM(LTRIM(notes)) But it does not work. Is there any alternate way to do it? ...

getting the autoincremnt value after inserting record using SQL Server

Hi Guys I'm developing a project using VB.NET connected to SQL Server database and in this project i need to get the value of column called "ID" after inserting a record to the database immediately. thanx. ...

importing a sql ddl file into Microsoft SQL server

how to import a SQL ddl file into ms sql server 2005? ...

Reading Tables and columns in SQL SERVER using C#

Is it possible to determine the tables and its column in SQLserver in a particular database using c#? Can any one guide me in this issue? ...

SQL server SP : sometimes not to be included in WHERE clause

I am very new to SQL Server Stored Procedures, This is My SP : CREATE PROCEDURE [dbo].[spGetBonusRunDetails] ( @StartDate as DATETIME, @EndDate as DATETIME, @PageNumber int, @PageSize int, @Status int ) AS ;WITH DataCTE AS ( SELECT ROW_NUMBER() OVER(Order by Id) as RowNumber ,[StartDateTime] ,[EndDate] ...

Table design and performance related

I have a table with 158 columns in SQL Server 2005.any disdvantage of keeping so many columns. Also I have to keep those many columns, how can i improve performance - like using SP's, Indexes? ...