sql

SQL delete operations not rolled back

When I rollback a transaction it rollbacked only update and insert operations, but delete operations are not rollbacked, I want to know the reason? I am using insert, update and delete operations under one SQL transaction ...

Best approach to remove time part of datetime in SQL Server

Which method provides the best performance when removing the time portion from a datetime field in SQL Server? a) select DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0) or b) select cast(convert(char(11), getdate(), 113) as datetime) The second method does send a few more bytes either way but that might not be as important as the speed ...

How to make result set from ('1','2','3') ?

Hello! I have a question, how can i make a result set making only list of values. For example i have such values : ('1','2','3') And i want to make a sql that returns such table: 1 2 3 Thanks. [Edit] Sorry for wrong question. Actually list not containing integers, but it contains strings. I am currently need like ('aa','bb,'cc'). ...

How should I document an existing system

Hi there, I've just started at a new job with sole responsibility for a large(ish) financial application. It's got about 800 stored procedures, 120 SQL server tables and 18 .net projects with approx 1200 code files. And no documentation other than line comments in the code. As I mend bugs and make ad hoc to the data I want to document w...

How to export text data from a SQL Server table?

I am trying to use the MS SQL Server 2005 Import/Export tool to export a table so I can import it into another database for archival. One of the columns is text so if I export as comma-delimited, when I try to import it into the archive table, it doesn't work correctly for rows with commas in that field. What options should I choose to e...

postgres: How to prevent INSERT in a special case

Hi there, I got a table 'foo' that looks like ID | NAME ------+---------------------------- 123 | PiratesAreCool 254 | NinjasAreCoolerThanPirates and a second table 'bar' SID | ID | created | dropped ------+------+------------+----------- 9871 | 123 | 03.24.2009 | 03.26.2009 9872 | 123 | 04.02.2009 | b...

Finding columns that do not match existing primary key

I'm trying to add a Foreign Key to a table, but database, Sql Server 2005, does not like it. It says that columns do not match an existing primary key or unique constraint. How can I find the columns in question so I can delete/change them and add the foreign key? ...

Data Type Mapping

Hi , I need to store XML data to database(MS SQL Server). The data type defined in the column is text. I need to know the the equalent datatype for text. I have tried with adLongVarChar but it does not works. Also I tried with adLongVarWChar(nText). But both are not working. Need help. Thanks. ...

Recommended books on SQL Server 2005 full text indexing

I am looking to learn more about full text indexing and I am looking for more information than is available in SQL Books online or at least something that presents full text indexing in a different way. Does anyone have any recommendations on books. ...

Good books or sites for advanced SQL queries or puzzles?

I work with SQL almost on a daily basis and want to improve my SQL skills. I am looking for online resources or books for advanced queries for real life problems. I liked Joe Celko's books and I am looking for similar resources. I am also interested in SQL puzzles but ones which solve real life business apps. I am not into brain teasers,...

Setting the minimum column width in SSRS

Greetings. For the life of me, I can't remember how to set the minimum width on an SSRS column. When I render the report in 'Preview' mode it looks fine, but when I set it up as a subscription to go out via email it gets scrunched together. Appreciate any help. Thanks! ...

Stored Procedure To Table Variable Issue

Okay, what I'm trying to do is take the results from a stored procedure and put them into a temp table... Looks like this: DECLARE @Table TABLE( [ID] int, [CostA] real, [CostB] real, [CostC] real ) INSERT INTO @Table EXECUTE [dbo].[CostProcedure] @RootId = 123 @Rate = 20 --THEN: SELECT * FROM @Table -- Gives Me...

SQl Query :Joining 4 Tables :One to Many

I have 4 Tables in my SQL server DB . OrderMaster,OrderDetails,ItemMaster,ManufacturerMaster OrderMaster ( OrderId [primaryKey],Orderdate,TotalAmount,SupplierName) OrderDetails (OrderDetailId[primaryKey],OrderId,Item_Id,Quantity,ManufacturerId) ItemMaster (Item_Id [primaryKey],ITem Name,ITemCost,) ManufacturerMaster (ManuId[primaryKey],...

How to return all records for Gridview select command parameter.

Using asp.net In the gridview select command, how can I select all records, including null, for a particular field. I have a parameter which changes with the dropdown selection. I have a default list item set to % but this will not pull records with null. I tried this: Where ((@submit LIKE '%' AND user_submit LIKE @submit OR user_sub...

How to find the type, length, nullable or not given a table and a field name

I have a table that has data that maps to fields in other tables in the database. Something like this: FieldName isNeeded CUSTNAME 0 PRODQTY 1 The MYFIELD1 and MYFIELD2 maps to fields in other tables. In a SQL Script, I would like to get the field definition such as type, length (info that we get we run a sp_help ...

Trimming alphanumeric characters from a strings of varying lengths in T-SQL

I have a result set that I want to trim a 2 digit suffix from. The strings will always be of varying lengths, but the suffixes will always be two digits separated by '-'. Example: APPTR-W302-01 NRSB-8920-09 Right now I am using the following. This is a hack because the '20' parameter is arbitrary. REVERSE(SUBSTRING(REVERSE(COURSENAME...

Using multiple tables in MySQL and/or multiple columns for a Rails application

Hello, I'm wondering what the best practice is for having redundant columns in a MySQL database. I'm wondering this because I have a User table in my database but I also want to be able to display many statistics about each individual user. These stats might include how many times a user has interacted with another model or how many me...

Multiple SQL searches vs searching through one returned array

Is it faster to do multiple SQL finds on one table with different conditions or to get all the items from the table in an array and then separate them out that way? I realize I'm not explaining my question that well, so here is an example: I want to pull records on posts and display them in categories based on when they were posted, sa...

How do I select the rows of a table that don't match another table in SQL?

I am trying to display all the names from the table vocabulary where the vids do not match a vid in collapse_menu. How would I do this? Table vocabulary vid name 1 Sections 2 Posts 6 Forums 5 Departments 13 Free Tags 8 Committees 9 Training and Workshops 10 Policies 12 Projects ...

What does keyword CONSTRAINT do in this CREATE TABLE statement.

I'm learning how to use sqlite3 with python. The example in the text book I am following is a database where each Country record has a Region, Country, and Population. The book says: The following snippet uses the CONSTRAINT keyword to specify that no two entries in the table being created will ever have the same values for r...