sql-server

SQL Query to calculate weight or distribute weight based on value/null

I have a table with columns - id, x1, x2, x3,x4 if i have values 1,y,y,y,y 2,y,null,n,null 3,y,null,null,null then say, i want to calculate (1)/(number of y's) and display rows as 1,.25,.25,.25,.25 2,1,0,0,0 3,1,0,0,0 Is it possible to do this using sql query? ...

SQL joining with parameter problem

I asked this question before: http://stackoverflow.com/questions/1921818/how-do-i-bring-back-an-entire-range-of-dates-in-sql-between-two-dates-even-when but I now need to only select incidents that have a Status of "E" for emergency. I can't put WHERE status='E' though, because that will stop it returning an entry for every single dat...

Convert pair comparison sql for MS SQL in Hibernate

We use hibernate to handle different databases. There's a problem about using pair comparison sql when the data source is MS SQL. We want to know how to convert this statement for ms sql. The following is the simplified sql. notice: column1 and column2 both are uuid and numeric type. ( in ms sql will be numeric(19,0) the converted s...

SSRS Excel output sorting image problem

Hello, When exporting my simple data report to Excel (Using ReportViewer in localmode) I can sort the table data fine but I have images in all of the rows and they do not sort with the data. My basic setup is a C# class that provides a List<> of a data type with a few columns and a byte[] image in it as an object data source. I just d...

deleting multiple records from two tables

I have two tables called TableA and TableB. TableA has the following fields: TableA_ID FileName TableB has the following fields: TableB_ID TableA_ID CreationDate There is a foreign key link between the two tables on the TableA_ID field I need to delete records from both tables. I need to look at the “CreationDate” on TableB and ...

sorting the grid

Hi, Iam working on sorting the grid remotely. Iam using the folllowing query SELECT value a, ROW_NUMBER() OVER (ORDER BY" + " " + SortExpression + ") As RowNumber FROM XSP_AssetList_V AS a WHERE a.AccountID = GUID'" + AccountID + "'"; is there any linq equivalanet for rownumber() over orderby() but iam getting an error System.Dat...

Ordering by a Column that's not in the Group By or Enapsulated in an Aggregate

I have a problem getting this JPA query to work on MS SQL Server 2008. The background is as follows: Users create jobs for clients, of which there are many. I am displaying a list of his most recently used clients to the user to make the selection easier. SELECT DISTINCT c FROM Client c JOIN c.jobs j WHERE j.user = ?1 O...

Use SOUNDEX() word by word on SQL Server

Hi there, Here is my problem. For example I have a table Products that contain a field Name: Products ID | Name | .. 1 | "USB Key 10Go" 2 | "Intel computer" 3 | "12 inches laptop computer" ... I'm currently implementing a simple search engine (SQL Server and ASP .NET, C#) for an iPhone web-app and I would like to use the SOUNDEX()...

sql server 2000 TSQL: creating index on table variable

Is the following possible? I am unable to do so. Do I have to have a permanent table to create index? declare @Beatles table ( LastName varchar(20) , FirstName varchar(20) ) CREATE CLUSTERED INDEX Index_Name_Clstd ON @Beatles(LastName) ...

Execute function inside view SQL server

I have SQL function and i need to execute it inside SQL view. any suggestion.. ...

How do table indexes come into play when using a view?

I have a view that collects data from several tables. While there are no indexes on the view itself anything that uses the view seems to benefit from the underlying tables having indexes. Are these being used automatically? If they are then what is the point of creating indexes on your views? Any recommended articles on this subject ...

How to turn on the FULLTEXT mode on SQL Server 2005

Hi, I'm currently trying to create FULLTEXT indexes into my database (Microsoft SQL Server 2005). First I want to create the catalog: USE [AspDotNetStorefront] GO EXEC sp_fulltext_database 'enable' GO CREATE FULLTEXT CATALOG searchcatalog GO But that doesn't work, the result is this: Msg 7609, Level 17, State 100, Line 1 Full-Text...

SQL Server: convert ((int)year,(int)month,(int)day) to Datetime

Possible Duplicate: Create a date with T-SQL Hi, I've a data table that stores each year, month and day value as ints: year | month | day 2009 | 1 | 1 2008 | 12 | 2 2007 | 5 | 5 I need to convert it to datetime value, because I need to use it in a datetime between operation. How could I do this? Thanks, b. ...

SQL Server Import and Export Wizard Error

I'm trying to import an 82k+ row table from an access db to SQL Server 2008. Using the SQL Server Import and Export Wizard, I get an error at about 78k records entered. Here's the error: Error 0xc0208265: Data Flow Task 1: Failed to retrieve long data for column "members_notes". Error 0xc020901c: Data Flow Task 1: There was an error...

SQL CE: Limiting rows returned in the query

In SQL Compact Edition 3.5 , note that it is the Compact Edition I am talking about- Is there a way to limit the amount of rows to only 2? Something like using LIMIT or TOP. I really don't want to use anything with a SqlCEDataReader, or SqlCEResultSet. I want to do all the limiting in the query. Is this possible now? I have looked around...

Select datetime data from SQL Server colum

SELECT [NEXT_UPDATE_TIME] FROM [BGREX_UpdateQueue] WHERE [NEXT_UPDATE_TIME] < 18/12/2009 I want to select those dates from the records where datetime value in column is less than some datetime, we need to compare. I have several value lass than "18/12/2009", but getting no rows returned. following syntax does not work either SELEC...

Improving performance on a view with a LOT of joins...

I have a view that uses 11 outer joins and two inner joins to create the data. This results in over 8 million rows. When I do a count (*) on the table it takes about 5 minutes to run. I'm at a loss as to how to improve the performance of this table. Does anyone have any suggestions on where to begin? There appear to be indexes on al...

Sql Server merge replication primary key violations

Using Sql Server 2008. Pretend I have a publisher and 2 subscribers A and B. The replicated table has a guid on it and also a primary key that is not the guid. Frequently, updates happen at both subscribers near simultaneously generating 2 different guids but the same primary key. Then when they go to syncronize I get primary key vio...

update DateTime value in Table using SQL

How can we update datetime value in a column using sql say, if we want to update any of datetime values by adding an hour or 5 minutes etc. UPDATE TableLastCalls SET [NEXT_UPDATE_TIME] = ?? // want to add an hour ...

How do I extract just the date from a SQL datetime value in SSIS?

How do I convert a datetime to just a date in SSIS? I'm trying to perform an aggregate query which will group by a particular date. In order to do that, I'm trying to extract just the date portion of the timestamp(stored as a datetime) so I can perform the GROUP BY on the next step. I've looked at the DATEPART function, but it looks l...