sql-server

Dynamic sql query

Hi there.. This is my query... but it returns incorrect syntax near '+' DECLARE @refKlinik_id INT SET @refKlinik_id = 24 DECLARE @kriter VARCHAR(50) IF @refKlinik_id <=0 BEGIN SET @kriter = '' END ELSE SET @Kriter = 'AND H.refKlinik_id =' + @refKlinik_id SELECT H.adi + ' ' + H.soyadi AS Hasta, H.tcKimlikNo, CONVERT(...

What is the preferred way of executing SQL in a Custom SSIS task?

I'm writing a Custom SSIS task that, as one of it's functions, should execute a stored procedure on a database connection. I can't seem to find any information about how this is done. I'm using an ADO.NET Connection Manager to connect to the database and I wish to write my Task in C#. What is the preferred way of executing SQL in a Cu...

SQL Server Query

I have following tables: Table Name : LandParces Blockid, PNo, Name, Address ========================================= 32000101 5 Chandana De Silva Colombo 32000101 8 Fernance Badulla 32000203 4 Sunil Fernando Tangalle Table Name = Owner Blockid, PNo, StorP Hec =============================...

SQL Syntax: Select Results for each date between a range of dates

Hi, I have the following SQL (SQL Server 2005) that I use to calculate the total times for each column: DECLARE @Param1 DATETIME DECLARE @Param2 DATETIME DECLARE @Param3 DATETIME SET @Param1 = '2009-01-01' SET @Param2 = '2009-09-09' SELECT SUM(IdleSec) AS TotalIdleSec, SUM(ProductionSec) AS TotalProductionSec, SUM(Upline...

Attach SQL Server mdb file at runtime

I want to attach SQL Server 2005 database at runtime. Can this be achieved without using local instance of SQL Server i.e. even without SQL Server Express? Currently I'am using following connection string is there any other workaround. Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connectio...

How to return temporary table from stored procedure

CREATE PROCEDURE [test].[proc] @ConfiguredContentId int, @NumberOfGames int AS BEGIN SET NOCOUNT ON RETURN @WunNumbers TABLE (WinNumb int) INSERT INTO @WunNumbers (WinNumb) SELECT TOP (@NumberOfGames) WinningNumber FROM [Game].[Game] g JOIN [Game].[RouletteResult] AS rr ON g.[Id] = rr.[gameId] WHERE g.[ConfiguredContentId] =...

Query to list number of records in each table in a database

How to list row count of each table in the database. Some equivalent of select count(*) from table1 select count(*) from table2 ... select count(*) from tableN I will post a solution but other approaches are welcome ...

How do I convert this PL/SQL update statement so that is works in SQL SERVER?

I've been asked to convert this statement from PL/SQL to SQL Server: UPDATE pdi_nb_process_complete pdi_end1 SET (pdi_end1.adp_issue_date_time, pdi_end1.adp_print_date_time) = (SELECT DISTINCT pdi_end1.completion_date + 2 ,pdi_end1.completion_date FROM cl100 cl WHERE cl.polref = pdi_end1.policy_reference AND ...

O/RM Choice (not reliant on linq)

Hey Everyone, I like using SQL, and I think I am pretty good with it. And I tried to use Linq (with c# and Linq2Sql, looks like it feels more SQL-like with VB.Net), I feel it is very frustrating, you cannot just run your query without compiling and executing the code. I am not so great with IQueryable, IEnumarable, IList etc. And I hav...

SQL Server express edition issue

Hello everyone, I want to know SQL Server Express edition, like SQL Server 2008 Express edition, whether totally free or not (e.g. free for a period of time or free for ever)? I heard no management tool like SQL Server Management Studio for Express edition, is that true? If I have some code which works on SQL Server Enterprise edition...

Performance issue with SQL Server stored procedure

I used the ANTS profiler to identify the remaining bottleneck in my C# application: the SQL Server stored procedure. I am using SQL Server 2008. Can anybody here help me increase performance, or give me pointers as to what I can do to make it better or more performant? First, here's the procedure: PROCEDURE [dbo].[readerSimilarity] --...

Entity Framework, full-text search and temporary tables

I have a LINQ-2-Entity query builder, nesting different kinds of Where clauses depending on a fairly complex search form. Works great so far. Now I need to use a SQL Server fulltext search index in some of my queries. Is there any chance to add the search term directly to the LINQ query, and have the score available as a selectable prop...

T-SQL ISNULL() Optimization

I have this clause on a join in a stored procedure I inherited: WHERE a.is_active = 1 AND b.due_date <= ISNULL(@due_date_limit, b.due_date) How would I re-write this to remove the ISNULL as it's causing severe performance problems? ...

SQL - Select statment using LastIndex

I have a resultset which has ProductURL stored : accessoires/abc/285/P187654 accessoires/abc/285/D18765432 accessoires/abc/285/A1876543 I need to get the final part of the URL i.e. anything that is after the final '/' that appears in the URL. I have a function which gives me the LASTINDEX : SELECT [LAST_INDEX] (ProductURL,'/') But...

Sql Server 2008 check constraint

I have two tables, Table1 and Table2 with same primary key (FKTestID). If I want to delete one row in Table1 and same FKTestID are in Table2 it will not work. You can only delete a row from Table1 if Table1.FKTestID not equals any FKTestID in Table2. Please help me with this constraint? ...

How to create Linked Server with non-default port.

I want to create a Linked Server in MS SQL Server 2000 to a MS SQL 2005 Server which runs on port x (not the default port 1433). But it doesn't work, as I can't specify the port anywhere!? Using sqlcmd (specifying port x), I can connect to the server without problems - but I can't set it up as a Linked Server. How can this be done? ...

Inserting German date format in SQL using VBA

I'm pretty frustrated here, been trying this for days... All I want is for German users to be able to enter dates that should be stored in SQL Server. The dates are in the following format "dd.mm.yyyy". I always get error messages like this one: Syntax error in date in query expression '#23.01.2004 00:07:00#'. - using Access for now. I'...

Copy Table from one to another server

Can any body let me know how can we copy a table with the data in it exactly to another server. I would really appreciate your help. ...

Impersonation for sp_OA* on SQL Server 2000

Is there any way to impersonate for sp_OA* calls? I'm specifically using this for file system management, and I'm doing everything in TSQL to avoid DTS since there's a possibility of upgrading to 2005 and I want this solution to be cross-version. Unfortunately, I need to access remote file systems but I can't get AD permissions added t...

Select From a Large table

Hi Friends, I hava very large table with 1373228 rows. I need to copy the result to excel but It does not allow me to do so. Can anyone please, suggest me that how can select the table in parts and paste it in excel. I would really appreciate it. Thanks a lot ...