sql-server

Sql Recursive query to identify relation between 2 users of family tree

Users Data UserId DisplayName 12 Rahul 13 Anjali 14 Faruk 15 Shabina 16 Shakira 17 Ali 18 Ronak 19 Dali 20 Bali 21 Kali 22 Katrina 23 Sita 24 Gita 25 Ram 26 Shyam 27 Suhana 28 Suhas 29 Raj 30 Taslim 31 Ritik 32 Tejas 33 Dipika 34 Bush 35 Dyna 36 Bushiar 37 Salman 38 Ruksana 39 Khushi 40 Tazz 41 Miki 42...

SSIS how can i insert a blank date to database with visual basic

Hi all, how can i insert a blank date to sql database in ssis working with a visual basic script component? I have to transfer date from excel to database and i would like to insert a blank or null value in the database if in the excel is empty thanks ...

dd/MM/yyyy in SQL Server

I have a DATETIME column "EntryDate" and I am storing values as dd/MM/yyyy format. But when I fetch records through SQL I don't get the expected result. For ex: I have 90 records from date 23/10/2009 to 23/11/2009. I get only 5-10 records. Why is this ? Here is my query : SET DATEFORMAT DMY; SELECT * FROM salesorderlist so LEFT JOIN...

Getting only Month and Year from SQL DATE

I need to access only Month.Year from Date field in SQL Server. Thanks in advance. ...

Why use database schemas?

I'm working on a single database with multiple database schemas, e.g [Baz].[Table3], [Foo].[Table1], [Foo].[Table2] I'm wondering why the tables are separated this way besides organisation and permissions. How common is this, and are there any other benefits? ...

What is the difference between these two queries?

I am writing my join query by the following way UPDATE UPLOAD_TEMP SET UPLOAD_TEMP.Borr_Add_Req = t2.YesNoResponse, FROM UPLOAD_TEMP t1 INNER JOIN GB_RequiredFields t2 ON t1.State = t2.StateCode AND t1.County_Id = t2.CountyId AND t1.Grou...

Duplicates without using While or Cursor in T-SQL

ID Name 1 A 1 B 1 C 2 X 2 Y 3 P 3 Q 3 R These are the columns in a table. I want to get output like ID Company 1 A,B,C 2 X, Y 3 P,Q,R Restriction is that I cannot use WHILE or CURSOR. Please write a query for the same. ...

How to insert a value in the table?

Using VB.Net Am new to vb.net, Am using datagridview DataGridview ID Name ComboboxColumn 001 Raja 002 Ravi 003 Suresh ..., "Save" - Button In a Datagridview am Using combobox column in a third column Suppose If i select the value from the combobox, then i Press the save button means, The Datagridview column value should save in ...

When do you compact a Sql Server Database?

We have a SQL Server 2000 database that holds most of our teams databases running on a relatively old server. Lately we have been having some weird slow down issues on some of our database calls in various applications. (So I know it isn't application specific) It was mentioned to me that we should look into compacting some of our d...

Using Parameters in DATEADD function of a Query.

I am trying to us the DateAdd function of SQL in my Query. The problem is when I use a parameter to set the second arguement, the number argument I get an error which will say something like this: Failed to convert parameter value from a Decimal to a DateTime While if I enter it parameterless, i.e hardcode an Int, it works fine. ...

Problem with SQL In Line Table Function... Query

Hi I have the following query running a function to get the Standard Deviation for a set of Tickers in the following table... GO CREATE TABLE [dbo].[Tickers]( [ticker] [varchar](10) NULL, [date] [datetime] NULL, [high] [float] NULL, [low] [float] NULL, [open] [float] NULL, [close] [float] NULL, [volume] [float] NULL, [time] [datetime] ...

SQL Server: Self-reference FK, trigger instead of ON DELETE CASCADE

Hello, I need to perform an ON DELETE CASCADE on my table named CATEGORY, which has the following columls CAT_ID (BIGINT) NAME (VARCHAR) PARENT_CAT_ID (BIGINT) PARENT_CAT_ID is a FK on CAT_ID. Obviously, the lovely SQL Server does not let me use ON DELETE CASCADE claiming circular or multiple paths to deletion. A solution that I see o...

Count of items per date, with no gaps in the dates

I have a table of posts to a website, where each entry has its creation date. I want to return a table like: Date Posts 16-11-2009 5 17-11-2009 0 18-11-2009 4 etc But I'm struggling to find the right SQL. I can easily get a count of posts grouped by date, but this doesn't return the dates when there are no posts (eg it...

PHP + SQL Server + SQL Server Driver = sqlsrv_num_rows serious problem

I have serious problem in my application. When I make 'CTE' select in my SQL Server database and then I use sqlsrv_num_rows to count rows amount in result object I got strange result: -1. This value is not even in manual (link: http://msdn.microsoft.com/en-us/library/ee376931(SQL.90).aspx). Sample code: W have select 'CTE - Common Ta...

IF statement within SQL Query

I have the following query, that makes up a View. I'm having trouble with the IF statement within it. Basically, if salesHeader.[Ship-to Name] isn't null, i need to return that AS DeliveryName, if it is null, return something else. There are several fields like this (i've only included one for now) Is there a way of doing this? SELE...

SQL Server 2008 SSIS package compatability

I am trying to save an SSIS package on a sql server running 2005. The issue I have is that I am using SQL Server Management Studio 2008 on my local machine to do this and it won't let me save the package in on the server because its not compatible with 2008. Is their some kind of compatibility option in management studio that I don't kn...

Exclude row if one of 2 flattened columns didn't return

Hello, I am joining against a view, in a stored procedure to try and return a record. In one table I have something like this: Measurement | MeasurementType | Date Performed I need to plot TireHeight and TireWidth. So I am flattening that table into one row. I only want to return a row though if both TireHeight and TireWidth were ...

What's too much SQL Server data and how do I analyze my execution plan

I have a relation between two tables with 600K rows and my first question is, is that a lot of data? It doesn't seem like a lot (in terms of rows, not bytes) I can write a query like this SELECT EntityID, COUNT(*) FROM QueryMembership GROUP BY EntityID And it completes in now time at all, but when I do this. SELECT EntityID, COUNT(*...

Doing large updates against indexed view

We have an indexed view that runs across three large tables. Two of these tables (A & B) are constantly getting updated with user transactions and the other table (C) contains data product info that is needs to be updated once a week. This product table contains over 6 million records. We need this view across these three tables for ou...

SQL Server 2005 Caching

It's my understanding that SQL Server 2005 does some sort of result or index caching. I'm currently profiling complex select statements which take several seconds to several minutes to complete. My problem is that a second run of a query never takes more than a second to run even if I don't alter it. I'm currently using SQL Server Manage...