Need help with a SQL join: Conditional Matching?
I'm joining 2 tables. ACCOUNTS account_number region product 1234 100 AB 2345 0 AB 3456 300 CD 4567 0 CD PRODUCTS product region price AB 100 $1.50 AB 0 $1.25 ...
I'm joining 2 tables. ACCOUNTS account_number region product 1234 100 AB 2345 0 AB 3456 300 CD 4567 0 CD PRODUCTS product region price AB 100 $1.50 AB 0 $1.25 ...
If you have a field(foreign key) in a table that can accept null until there is something in it, so after that the field would refuse null value. how would you do this? ...
Hi there, I have a database in SQL Server containing a column which needs to contain Unicode data (it contains user's addresses from all over the world e.g. القاهرة for Cairo) This column is an nvarchar column with a collation of database default (Latin1_General_CI_AS), but I've noticed data inserted into it via SQL statements contain...
I have a database which was upgraded from 2000 to 2005. Is there any issue using sp_dbcmptlevel to change compatibility level to 90. Will this cause any issues with old queries or stored procedures ...
Hello, When I select from SQL Server, I want to get a date, but omit the millisecond value, and I want it to be as a date type. So if I have a value 1/1/2009 1:23:11.923, I want to omit the millisecond but retain the date type, so that it will be the value 1/1/2009 1:23:11.000 (I know you really can't omit the millisecond value with a ...
I'm trying to write a sql statement which returns bad rows from my table. I have a table with rows: Key | Date | Indicator 1 | 10/10/08 | SE 1 | 10/11/09 | CB 1 | 10/12/09 | CE 1 | 10/13/09 | TR 2 | 1/1/09 | SE 3 | 10/10/08 | SE 3 | 10/13/09 | CE 3 | 10/15/09 | SL So what I want returned would be all rows where a key has an in...
I am trying to determine what indexes are no longer used in my Database. I have had great luck using the following query: SELECT OBJECT_NAME(S.[OBJECT_ID]) AS [OBJECT NAME], I.[NAME] AS [INDEX NAME], i.Type_Desc as [Index Type], USER_SEEKS, USER_SCANS, USER_LOOKUPS, USER_UPDATES F...
DB: SQL Server 2005 We have a table that has data in this manner: Project Year Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov ...
I would like to create a stored procedure that takes in a string of comma separated values like this "1,2,3,4", and break it apart and use those numbers to run a query on a different table. so in the same stored procedure it would do something like select somefield from sometable where somefield = 1 select somefield from sometable wher...
Hi, my default SQL Server 2005 log directory is full on C drive. In order to prevent this issue happening in future, I plan to move the default log directory to some other place. Could you please tell me how I can move the error log default directory? I browsed the web, there is solution for SQL Server 7 and 2000 but not 2005. Please ...
I've used the Access 2007 upsizing wizard to move my files to a SQL server. A problem I'm experiencing now is that when I try to link the tables in either Excel or Access, it requires me to create a DSN or a machine data source connection. In either case, when I do this, it makes the connection only useful on the current PC. What I'...
If I have a view, and embed the view in a query, will the view have to be processed fully before the rest of the query? Example: CREATE VIEW dbo.ExpensiveView AS SELECT IndexedColumn, NonIndexedColumn FROM dbo.BigHairyTable WHERE NonIndexedColumn BETWEEN 500000000 AND 500050000 GO SELECT * FROM dbo.ExpensiveView WHERE In...
I ran this query: SELECT i.name AS IndexName, s.used_page_count * 8 AS IndexSizeKB FROM sys.dm_db_partition_stats AS s JOIN sys.indexes AS i ON s.[object_id] = i.[object_id] AND s.index_id = i.index_id WHERE s.[object_id] = object_id('dbo.Stu') ORDER BY i.name and the largest index returned ...
Using SQL Server 2005, I'd like to run a stored procedure and insert all of the results into a new table. I'd like the new table to have its columns automatically configured based upon the data returned by the stored procedure. I am familiar with using the SELECT ... INTO syntax: SELECT * INTO newtable FROM oldtable Is this possibl...
I have a sql script to create a new database which i need to create when our product is installed. For this i need to fire the script using c#. DB is sql-server 2005 express. Plz help.... The sql script is as follows: USE [master] GO /****** Object: Database [Jai] Script Date: 02/12/2010 11:01:25 ******/ CREATE DATABASE [Jai] ON P...
Is there any way of aliasing datatypes in T-SQL (SQL Server 2005), a bit like a C typedef? I'd like to be able to alias, say, VARCHAR(20) as 'my_datatype' so that wherever I wish to use VARCHAR(20) I could instead use my_datatype. Synonyms allow you to do this sort of thing for tables, and there are built-in synonyms for some datatypes ...
The table I am working on has a primary key which is essentially a version number. A couple of examples of the version number are below: 1.0.0.0 1.1.2.24 Varchar seemed the most obvious choice to me, but I'm looking to set the primary key as a clustered index - I have read on SQL performance sites that you should avoid using varchars ...
HI, This should be easy but I don't understand enough about how grouping works. Basically I have 2 tables "Categories" and "Items" Categories ID CategoryName Items ID CategoryID ItemName Photo Score All I want to do is get 1 row for each category which contains the Category ID, the Category Name and the photo that belongs to the h...
I installed SQL Server 2005, and I want to install service packs, I have service packs 1, 2, 3, but I want to know, Is it different to install just service pack 3? or I should install first SP1, the SP2 and finally SP3? ...
I'm looking for a way to automated the generation of change scripts for our databases. Currently we use Visual Studio 2008 database edition, which has the Schema Compare option, but I don't see a way to automated those actions. What I'd like to do is create an old and a new database during my daily builds and have schema compare gener...