sql-server

How to insert a foreign key using a Sub-SELECT in SQL Server

I've just started working with SQL Server for the first time and I'm having trouble populating test data. I have two tables where one has a foreign key to the other and I would like to be able to insert a new record using the following SQL: insert into Employee ( EmployeeName, DepartmentId ) values ( "John Doe", (select ...

Search based on matched criteria

I'm using the following query to return all records where at least 2 conditions match (provided by Quassnoi). SELECT * FROM ( SELECT ContentID FROM ( SELECT ContentID FROM VWTenantPropertiesResults WHERE ContentStreet = 'Holderness Road' UNION ...

How can I improve this convert(int,myColumn) query?

SQL Server 2000 Background I've got a table that stores miscellaneous meta data about a specific course in my course table. The table is defined: create table course_prefs { id int identity not null, crs_nbr int references course (crs_nbr) not null, fiscal_yr int not null, group_name varchar(50) not null, item_name varchar(50) null, ...

Next log backup - will it contain any transactions?

I'm trying to efficiently determine if a log backup will contain any data. The best I have come up with is the following: DECLARE @last_lsn numeric(25,0) SELECT @last_lsn = last_log_backup_lsn FROM sys.database_recovery_status WHERE database_id = DB_ID() SELECT TOP 1 [Current LSN] FROM ::fn_dblog(@last_lsn, NULL) The problem is w...

Microsoft.ExceptionMessageBox not being "found"

I have a winform solution that I deploy through clickOnce. There is the Main Project and then a Project called psWinForms. That project has a Reference to Microsoft.ExceptionMessageBox that I use in my custom error reporting. I have psWinForms as a reference in my Main Project with Copy Local = True. I have Microsoft.ExceptionMessa...

Is SQL Server 2008 compatible with 2005?

I have a problem with my website. When I publish my site on server, I got an error message: The database '----------------------------.MDF' cannot be opened because it is version 655. This server supports version 611 and earlier. A downgrade path is not supported. What can I do about this? ...

How to combine assignments by date range from two data sets into a single data set containing unique overlaps

I have a table that houses assignment attributes for people and the date ranges that each attribute was assigned for. The table has the following fields: PersonId, AssignmentType, AssignmentValue, StartDate, EndDate Each person has an assignment type of racfId and cmsId which can independently start and end at arbitrary times. What i a...

Query engine for a variable data source. C#

I have a growing set of Excel spreadsheets none with the same data structure. I need a mechanism to query each of these spreadsheets (DataTables) using a single interface. So essentially, you choose the DataTable from a dropdownlist and then perform your search. My initial thought was to handle it like this. Create a generic data str...

Can SQL Server bcp in a file with Unix line endings?

I'm trying to use the SQL Server bcp utility to import a text file from a samba share. bcp is choking on the Unix line endings. I'm sure I could add an intermediate step, either on Unix or Windows, to change the line endings to Windows-style. But I would prefer to import the files from Unix without modification. Anybody know if there's ...

How do I select one parent row and additional rows for its children without a UNION?

I have a parent and child table and want to create a select statement that, given a parent id, returns a row for that parent and additional rows for every child. Doing a left join is not giving me a row for the parent by itself when one or more children exist. I know this can be done with a UNION but I'm looking for a solution that does ...

do you have to specify the length of the type in a sproc parameter?

Does SQL Server allow you to declare stored procedure parameters like this? @username NVARCHAR Or do you always have to specify a size like this? @username NVARCHAR(100) ...

NHibernate Naming Conventions - Eliminate Keyword Conficts

How do I escape keyword conflicts when NHibernate generates my column names using FluentNHibernate? NHibernate generated this for me and "Key" is a conflict. create table Setting ( Key NVARCHAR(MAX) not null, Value NVARCHAR(MAX) null, primary key (Key) ) ...

TABLE1 T1, TABLE2 T2 WHERE T1.Blah = T2.Blah - VS - INNER JOIN

Provided that the tables could essentially be inner joined, since the where clause excludes all records that don't match, just exactly how bad is it to use the first of the following 2 query statement syntax styles: SELECT {COLUMN LIST} FROM TABLE1 t1, TABLE2 t2, TABLE3 t3, TABLE4 t4 (etc) WHERE t1.uid = t2.foreignid AND t2.uid = t3.for...

OUTPUT clause for Stored Procedure vs Table-Valued Function

I'm studying for the MCTS 70-433 "Database Design" cert, and in the text that I'm studying, one of the self-tests has this question. You have a stored procedure named Get_NewProducts. You wish to insert the results of this stored procedure into the Production.Product table and output the INSERTED.* values using the OUTPUT ...

How to Programmatically Disable Named Pipes in SQL Server 2005 Native Client?

How to Programmatically Disable Named Pipes in SQL Server 2005 Native Client? ...

Can a Microsoft Access Forms application be switched to work with a SQL back end?

Hi, I was asked to provide an estimation to change a relatively small app designed with MS Access to use a SQL database. First, is this even possible? I never worked enough with Access, so I'd like to know. If it's possible can you please point me to some websites with tutorials regarding this? Second: if it's possible, is it recommen...

Sql server error : The INSERT statement conflicted with the CHECK constraint

The INSERT statement conflicted with the CHECK constraint "ck_str_member_no". The conflict occurred in database "C:\DOCUMENTS AND SETTINGS\KARTHIKEYAN\DESKTOP\KOK\DB\INFT3009_ASS1_C3104855.MDF", table "dbo.Members", column 'str_member_no'. The statement has been terminated. I am using .MDF file in my visual studio 2008 Express. How do ...

How to find out size of the individual databases in the sql server 2005?

Please tell the query to find out size of the individual databases in the sql server 2005? ...

how to find out log size of each of the database in sql server 2005?

Duplicate of: http://stackoverflow.com/questions/1496136/how-to-find-out-size-of-the-individual-databases-in-the-sql-server-2005 how to find out log size of each of the database in sql server 2005? ...

How to modify the date column values?

Using SQL Server 2000, Date Column Datatype is varchar... In my table date column values are like: 2009/01/31 2009/02/00 2009/02/01.... 2009/03/31 2009/04/00 2009/04/01.... so on..., I want to display 2009/01/31 instead of 2009/02/00, If date is 2009/02/00 it should display previous date. How to make a query for this condition? ...