sql-server

Linked server and temp table issue

I had our vendor create a linked server (SQL Server 2008) to our Server (SQL Server 2000). This was in response to an issue I had with the vendor changing a data type to varchar(max). I was informed that I should create a link from 2008 to 2000 to resolve the issue. Now that I have accomplished this task, when I run my query that links...

How to create a profile php code?

I just started with PHP and my SQL databases, I have learned how to create databases, and create register forms that store the information on the databases, but I do not know how to keep people from being able to register with a user name that has already been taken, and I don't know how to allow users to have their own profile page on m...

Capturing object dependencies at execution time in SQL Server

Is there any sane way to capture execution-time object dependencies in SQL Server? For instance, take this dynamic SQL scenario: DECLARE @table SYSNAME = 'SomeTable' DECLARE @column SYSNAME = 'SomeColumn' DECLARE @proc SYSNAME DECLARE @command NVARCHAR(MAX) = 'SELECT TOP 1 @proc = '+@column+' FROM '+@table EXEC sp_executesql @command, ...

Updating an Asp.Net MVC Database from a microcontroller

I've created a Asp.net MVC web application that has a SQL Server attached to it. I would like to update the database on an action (in this case a physical card swipe). I have a microcontroller that stores the identification number and then can connect via tcp to the site. What is the best approach for allowing the microcontroller to ad...

Urgent: slowness of execution of query

Hi guys kindly help, Ihave used following table lined functions in sql USE [EEMSPROD] GO /****** Object: UserDefinedFunction [dbo].[OpenTRF] Script Date: 08/21/2010 11:06:33 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER function [dbo].[OpenTRF]() RETURNS @TblOpenTRF TABLE ([Req No] NVARCHAR(50),[Travel from Date] date...

How do you export all tables to a CSV file using SQL Management Studio?

When I right click on the database I want to export data from, I only get to select a single table or view, rather than being able to export all of the data. Is there a way to export all of the data? If this is not possible, could you advise on how I could do the following: I have two databases, with the same table names, but one has ...

SQL Server Database Restore with ReadXML

I've backup from a sqlserver created with this procedure: protected void WriteXML(string tableName) { using (SqlConnection cnn = new SqlConnection(ConnectionString)) { using (SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM [" + tableName + "];", cnn)) { cnn.Open(); DataSet ds...

Help with a SQL query with a couple of foreign keys.

I have the following tables structure: Shipment (has IDDestination as foreign key) -> Destination (has IDCity as foreign key) -> City (has IDCountry as foreign key). I want to give my stored procedure a Country ID and have it return all of the shipments. How would I do this with pure SQL syntax? I could do this trivially with an ORM, b...

Deleted a table, created it again, now it doesn't appear in the dbo.

In SQL Management Studio, I deleted a table, and created it again using a SQL query. Now in code I cannot call it using dbo. something something. It just doesn't appear in the intellisense. Any suggestions on how to make this work? Edit: I can't delete the table again and RE create it with [dbo] tag. Any other solutions? ...

SQL server - Msg 213 - Insert Error: Column name or number of supplied values does not match table definition.

In SQL server, I am trying to insert values from one table to another by using the below query : delete from tblTable1 insert into tblTable1 select * from tblTable1_Link I am getting the following error : Column name or number of supplied values does not match table definition. I am sure that both table having same structur...

help with a sql query joining 2 many-many tables

i want help how to solve this sql problem. suppose i have 3 tables Movie ID Name Genre ID Name Movie_Genre (this one is the link for many to many) FK_MovieID FK_GenreID i want to select all the movies that are of genre 1 and genre 3 how is this possible? i can only select the movies of 1 genre but not the movies...

Are 'Primary Keys' obligatory in SQL Server Design?

Observe the following table model: CREATE TABLE [site].[Permissions] ( [ID] INT REFERENCES [site].[Accounts]( [ID] ) NOT NULL, [Type] SMALLINT NOT NULL, [Value] INT NULL ); The site.Accounts->site.Permissions is a one-to-many relationship so 'ID' cannot be made a primary key due to the uniqueness that a PK imposes....

Log4Net Database fun - connection strings!

This works on dev: <connectionString name="asdf" value="Data Source=.\;Initial Catalog=fmwebapp1;Integrated Security=True" /> <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> On live (a 64 bit VPS) this doesn't work: <connectionStr...

SQL AdventureWorks count employees by gender by city

Hi, I want to count the cities by gender, like this; City GenderFCount GenderMCount Redmond 10 20 Here is my query gets city and gender in AdventureWorks database select Gender,City from HumanResources.Employee as t1 inner join HumanResources.EmployeeAddress as t2 on t1.EmployeeID = t2.EmployeeID inner ...

Is there any way to get NHibernate to emit a deadlock hint?

Is there any way to get NHibernate to emit a deadlock hint? e.g. for SQL server "SET DEADLOCK_PRIORITY LOW". At the moment I'm just executing a raw SQL query. ...

Way to create a table from a flat file in SQL Server without knowing datatypes?

Is there a way to load a flat file into SQL Server as a new table without knowing the data types of the columns in the file? I know one can use BULK INSERT to load flat file data, but a target table must first be created that matches the datatypes in the incoming file. OPENROWSET requires the creation of a format file that specifies th...

SQL Server, How to DROP COLUMN if condition is satisfied?

Hello all! I have been trawling google for answers to this but no luck. Any help would be great! I have a SQL table: tblFeedback. It stores answers to feedback questions. The Questions are held in a different table: tblQuestions. The questions on the feedback form can be changed via a user interface, therefore when the user edits the q...

Are Hierarchical Rowsets supported by JET and SQL Server?

The OLE DB documentation documents a hierarchial rowset feature, with SQL examples, but doesn't indicate what DB providers support it. Do JET and SQL Server support this feature? And do they use the same sort of syntax as in the documentation, or their own extended syntax? ...

MSYSGIT BASH : Execute SQL against MS SQL Server

I'm running MSYSGIT on Windows and I want to be able to execute SQL statements against a SQL server directly from the bash console and bash scripts. Is this possible, and if so, how do I do it? Thanks! ...

NTEXT comparison

Hello all, What's the right way to compare NTEXT column with a constant value? If I use something like [ntext2] <> '1,032.5', I get this error: The data types ntext and varchar are incompatible in the not equal to operator. The best possible solution would be if comparison is implemented in the same way for any column type. (<...