sql-server

For what reason doesn’t SQL allow a variable to be assigned a value using syntax @i =100;?

Unlike programming languages, SQL doesn’t allow variable to be assigned a value using the following syntax ( instead we must use SET or SELECT ): @i=100; //error Is there particular reason why SQL doesn’t allow this? thank you ...

Bulk Insert or Another way to load a lot of data at once using C# and SQL server?

I have an application where a user can upload files and associate the files with a project. The projects can be duplicated. Here is an example of an object: Public class Project{ Int ProjectId{get; set;} string ProjectName{get;set;} List<int> FileIds{get;set} } When I go to duplicate the project, say, what is the best way ...

Create temp row for each row in existing table.

I have two tables. In the one table I have a list of dorm rooms with maximum occupancy like so: dorm_building | dorm_room | max_occupancy Then I have a list of students and the room they are assigned to like this: people_id | people_name | dorm_building | dorm_room I want to create a table that has a row for each potential occupant...

Query results to list in SP

Hey everyone, I'm sure this is discussed somewhere, but after searching for a while I can't find it. I'm building a stored procedure for SQL 2000 and I need to build a list of numbers that I can use in an IN function. The query looks like this SELECT DISTINCT type FROM dbo.table WHERE building = @currentBuilding This will return ...

SQL server file size affection on performance

I have two table in database A,B A: summary view of my data B: detail view (text files has detail story) I have 1 million record on my database 70% of the size is for Table B and 30% for Table A. I want to know if the size of database affect the query performance response time ? Is it beneficial to remove my Table B and store it on ...

Stored Procedure stopped working.

I have a stored procedure that I'm positive of has no errors but I recently deleted the table it references but imported a backup with the same name exactly and same column settings (including identity) that the previous one had but now it doesn't work. Is there any reason that having deleted the table but importing a new would break t...

SQL Server 2008 - Change the MaximumErrorCount or fix the errors.

I am trying to copy all the tables and views from a database on SQL Server 2005 to a database on SQL Server 2008 using the Import data wizard, but after running for some time it just copied 230 tables from 570 tables and views and gave the following warning. Warning 0x80019002: Data Flow Task 46: SSIS Warning Code DTS_W_MAXIMUMERRORC...

SQL Count function

I'm a student this is part of a homework assignment. Thanks for any advice. I have 2 tables. Employee has a column last_name, Job_title has a exempt_non_exempt column it's data type is bit. 0 for hourly 1 for salary The primary key and foreign key is job_title for both tables. I need to find out How many employees are salaried and how...

SQL server database design question

I have a Users table and a Totals table which has an integer field for the total number of users. I thought about writing a console app that counts the Users table and then updates the Totals table. And then make a Task scheduler events that executes this app every 10 minutes. Is there a more elegant way to do this? ...

SQL: Single select query from 2 Non-Joining tables

I have 2 tables which doesn't have any references to each other and I'm trying to create a third table (for reference lookup) by selecting from fields from both tables. TableA has an A_ID TableB has a B_ID I want to create Table C which has a 1 to 1 reference between A_ID to B_ID where A_ID = FirstID and B_ID = SecondID, I can't join ...

Converting project to SQL Server, design thoughts?

Currently, I'm sitting on an ugly business application written in Access that takes a spreadsheet on a bi-daily basis and imports it into a MDB. I am currently converting a major project that includes this into SQL Server and .net, specifically in c#. To house this information there are two tables (alias names here) that I will call Ma...

How do I program against a local database while I develop in ASP.NET MVC?

At my work I found out that we belong to some program with Microsoft and get access to various products because of it. I've downloaded Microsoft Visual Studio 2010. I'm not a professional programmer but I've dabbled before and I wanted to check out ASP.NET MVC. I know that I want to use some flavor of SQL Server and that I want to c...

SQL Server: list items between AA and AM

I'm looking to list all rows where the field starts between the range of AA to AM. I know I could to this by ORing a ton of LIKEs together, but is there a better way? I'm running SQL Server if that changes things. Thanks! ...

iODBC error trying to connect to MS SQL Server in PHP with unixODBC/FreeTDS

I am trying to connect to a remote MS SQL Server db from PHP on Mac (eventually on an Ubuntu server( with FreeTDS and unixODBC, but even though I seem to have everything set up properly, I'm getting iODBC errors, and I'm not sure how to get around them. I'm using MacPorts, so my config is: /opt/local/etc/freetds.conf:: [bti_db] host =...

How do you escape quotes in a sql query using php?

I have a query $sql ="SELECT CustomerID FROM tblCustomer WHERE EmailAddress = '".addslashes($_POST['username']) ."' AND Password = '".addslashes($_POST['password']) ."'"; // while printing, it will be SELECT CustomerID FROM tblCustomer WHERE EmailAddress = 'test@ab\'c.com' AND Password = '123' if we executing this in a mysql ser...

Performance of ON Clause over WHERE Clause

Can anyone please tell me Which of the following queries will have better performance? SELECT * FROM [TABLE1] T1 INNER JOIN [TABLE2] T2 ON T2.[FK_ID] = T1.[PK_ID] WHERE T2.[ACTIVE] = 1; SELECT * FROM [TABLE1] T1 INNER JOIN [TABLE2] T2 ON T2.[FK_ID] = T1.[PK_ID] AND ...

INDEX NAME on PRIMARY KEY

Hi, I would like create a table and add to it a Primary Key. As for my understanding MS SQL add a clustered Index on the Primary Key and will name it with a default name. I would like to know if is possible create a table and ASSIGN a custom name for the index created by default or how can i change the default name after the table as ...

Implementing IF Condition Within a T-SQL UPDATE Statement

Using T-SQL, I would like to execute an UPDATE statement that will SET columns only if the corresponding variables are defined. Here's a simple pseudo-tsql example of what I'm trying to accomplish: --Declaring vars @ID int, @Name nvarchar(20), @Password nvarchar(10) --Run the update UPDATE User SET IF LEN(@NAME) > 0 Name = @Name, ...

SQL Query Group By Help

Hi, I have the following data: cust subject date Cust1 Subject1 2010-12-31 21:59:59.000 Cust1 Subject1 2010-12-31 21:59:59.000 Cust4 Subject3 2011-02-27 21:59:59.000 Cust5 Subject1 2010-10-31 21:59:59.000 Cust5 Subject2 2010-10-31 21:59:59.000 Cust6 Subject2 2010-10-31 21:59:59.000 Cust6 Subject2 2010-12-31 21:59:59.000 I need to a...

PHP get Arabic Content from SQL SERVER

Hi, how can i get Arabic content when i run MSSQL_QUERY? it appears as ???? i tried to do this $res=mssql_query($q); $row=mssql_fetch_row($res) echo iconv("unicode","utf-8",$row[0]) but in this case it shows the value as Chinese letters as 潬穬 any suggestion is highly appreciated ...