sql-server

MS SQL Server: 'contains' vs 'charindex'

I have a problem with a query in ms sql server. I have a full text index on a column called "col1". The data in this column can get quite large (20, 30 kb +). I now want to search in this column for an exact phrase. I have been told that the "contains" function is the fastest function for this, but I am aware of at least 2 other ways of...

Efficent way to set date using week of month value

I have a week of month in sql and i need to generate a datetime varible from that.. fields i have are dayofweek, weekofmonth and month values. anyone know of a quick effective way to calculate this in mssql 2005? Thanks Keep in mind. if week of month is set to 5 it is the last week of the month Examples are i have DayOfWeek, month, yea...

How to implement high performance tree view in SQL Server 2005

What is the best way to build the table that will represent the tree? I want to implement a select ,insert ,update and delete that will work well with big data. The select for example will have to support "Expand ALL" - getting all the children (and there children) for a given node. ...

How can i change dataset cell format

if i use this query thath creates a table(look Table1), But VisitingGap column is not correct format. i used cast method to give format. But not working correctly.i need Table2 declare @date1 nvarchar(100) , @date2 nvarchar(100) , @countgap int,@count int set @date1='2009-05-12' set @date2 = '2009-05-13' set @countgap = 30 set @count=...

Upload a Massive CSV File to SQL Server Database

Hi, I need to upload a massive (16GB, 65+ million records) CSV file to a single table in a SQL server 2005 database. Does anyone have any pointers on the best way to do this? Details I am currently using a C# console application (.NET framework 2.0) to split the import file into files of 50000 records, then process each file. I uplo...

How to avoid Sql Query Timeout

I have RO access on a SQL View. This query below times out. How to avoid this? select count(distinct Status) from [MyTable] with (NOLOCK) where MemberType=6 The error message I get is: Msg 121, Level 20, State 0, Line 0 A transport-level error has occurred when receiving results from the server (provider: TCP Pro...

Auto generate key on JDBC insert in SQL Server

Is there a general, cross RDMS, way I can have a key auto generated on a JDBC insert? For example if I have a table with a primary key, id, and an int value: create table test ( id int not null, myNum int null ) and do an insert PreparedStatement statement = connection.prepareStatement("insert into test(myNum) values(?)", Statem...

Creating a SQL Server database from Python

I'm using Python with pywin32's adodbapi to write a script to create a SQL Server database and all its associated tables, views, and procedures. The problem is that Python's DBAPI requires that cursor.execute() be wrapped in a transaction that is only committed by cursor.commit(), and you can't execute a drop or create database statemen...

Use Ms SQL SERVER full text search to match words

I need to write a query in sql using full text that returns records in the order of matching words count exmaple: in data base row 1 = "brown cow" //1 match row 2 = "lazy dog" //2 matches User input: "The quick brown fox jumps over the lazy dog" both inputs would be return with row 2 on the top ...

Paging in GridView using SqlDataSource

I have a GridView that accesses data from a SqlDataSource in DataSet mode. I have paging enabled and it works, but on large datasets it takes an extraordinarily long time to pull data. It seems like the SqlDatSource is pulling all the data, and then it's being paged at the UI level. This is obviously a lousy solution. I've looked at htt...

SQL query Parent-child distinct

I have a pair of SQL server tables. P contains id and name. PR contains id, interestrate, tiernumber, fromdate, todate and P.id. PR may contain many rows listed per p.id / tier. (tiers are a list of rates a product may have in any given date period.) eg: Product 1 tier 1 starts 1/1/2008 to 1/1/2009 and has 6 rates shown 1 row per rate...

Optimization suggestions for sql server table

I have a table containing user input which needs to be optimized. I have some ideas about how to solve this but i would really appreciate your input on this. The table that needs optimization is called Value in the structure below. All tables mentioned below has integer primary keys called Id. Specs: Ms Sql Server 2008, Linq2Sql, asp.net...

Identity Insert missing in all relevant SSIS Data Flow Transformation objects?

Am I the only person on this particular planet that is inconvenienced by the lack of Identity Insert, missing in all relevant SSIS Data Flow Transformation objects? Only the Bulk Insert Task supports Identity Insert, what about elsewhere in SSIS? Is there a technical change in SQL Server 2008 that makes this very, very limited support ...

Determining items that join against the same set in T-SQL

I am writing a a report and was wondering if there is there any way to find items that join into identical sets? For example in the following query, I want to find all areas that join against the same set of products: SELECT Area.Name, AggregateSetOfProductsId FROM Area INNER JOIN AreaToProduct ON AreaToProduct.AreaId = Area.Id GROUP ...

Avoiding a nested subquery in SQL

I have a SQL table that contains data of the form: Id int EventTime dateTime CurrentValue int The table may have multiple rows for a given id that represent changes to the value over time (the EventTime identifying the time at which the value changed). Given a specific point in time, I would like to be able to calculate the count of d...

How to get a customer to understand the importance of a qualified DBA?

I'm part of a software development company where we do custom developed applications for our clients. Our software uses MS SQL Server and we have encountered some customers which do not have a DBA on staff to manage the databases or if they do, they lack the necessary knowledge to perform their job adequately. We are in the process o...

Calling a function from within a select statement - SQL

Hi guys I have the following statement: SELECT CASE WHEN (1 = 1) THEN 10 ELSE dbo.at_Test_Function(5) END AS Result I just want to confirm that in this case the function wont be executed? My reason for asking is that the function is particularly slow and if the critiria is true I want to avoid calling the function... Cheers Antho...

Change run action in Visual Studio database project

I have a database project in Visual Studio 2008, and I want the ability to run a preprocessor on my sql code (using it to allow for variable database names without resorting to dynamic sql). So I'd like to change what action occurs when I hit the run button to include running the code through the preprocessor automatically. Is there a ...

How to forcibly create stored procedure even if some error occure?

Hi, When i execute database script, i got errors in stored procedure then it couldn't create that stored procedure that have errors. I want to forcibly create stored procedure even if some error occur in stored procedure. Thanks in advance ...

How to code a button to get data from a table in database and display in datagrid view ?

I'm trying to code a button which has a SELECT statement to get information from one table but I want the information displayed in a data grid view. From the data grid view, this data will be stored in a different table within the same database. Previously i had used a list box to display the information but i could not save it in the ...