tsql

How to select only one full row per group in a "group by" query?

Hi, I have a (seems to be) very easy problem, but after searching for hours, I can't find anything helpful. Here's the problem: In Microsoft SQL, I have a table where a column A stores some data. This data can contain duplicates (ie. two or more rows will have the same value for the column A). I can easily find the duplicates by doin...

how to find a sql field name that has a record like '%text%'

i want to search all teh fields in my DB to find the field names that have in them a string that contains some text. im trying to find a table and field responsible for some 3rd party software actions that i am aonly able to see the values for. i want to use these values to find the table and field they are stored in. ...

How do I convert a Hex color to and RGB color using T-SQL

How do I convert a Hex color to and RGB color using T-SQL ...

How to compare values within the same table in TSQL elegantly

I've got a settings table constructed with 'category' determining different products, 'varname' being the variable name, and 'info' being the value of the setting. so, for instance, select top 6 category, varname, info from settings_table where NODE_NAME='HTT-COMM-A' and section='Module Settings' and category in ('ProductA',...

TSQL to know if database mirroring is setup for both PRimary and secondary server

Hi, I have Database mirroring setup between two SQl 2005 servers (no witness). Using Tsql, I want to find if there is a user database on both primary and mirror server. I can use the following on mirror: select * from sys.databases where state <>1 and database_id>4 What should i use for Primary server? Any help? Regards Manjot ...

GROUPING DATEs in sql

i have a table in which there are ids and resigning dates. a singlle id have more than one resigning date. how can i display the table in which one id have only one resigning date which is the latest ie the maximum date. can somebody help me plzz....thanx a ton ...

ALTER TABLE DROP COLUMN FAILED

I'm trying to clean up a database table and I'd really like to drop two columns as they should no longer be being used. 'Property' table - Unable to modify table. The index '_dta_index_Property_7_669245439__K1_K9_K8_K24_K4_2_5_6_13_22_25_26_29' is dependent on column 'AveragePriceMta'. The index '_dta_index_Property_7_669245439__K1_K9...

TSQL: Exact match with a SP using a LIKE?

Hello, I've a SP using a LIKE. Let's simplify it to: SELECT * FROM customers WHERE name LIKE '%' + @query + '%'. I'd like to use it for an (optional) exact match search without altering the SP but with a tricky parameter ;) Is there a way to "cancel" the 2 '%' with a clever @query? Thanks. ...

TSQL Optimal / Acceptable table column count

What is the optimal / acceptable column count when you are designing a table that serves as a datastore for huge forms to be filled? ...

T-SQL Query not bringing back a count of 0

Hi, I have a feeling I am making some sort of foolish mistake here, however I am trying to do a query over two tables. One table contains the value I want to aggregate over, in this case I have called if the StoreCharge table. The other table contains the values I want to count. SELECT StoreCharge.StoreId, COUNT(DISTINCT(ISNUL...

metaphone for asian languages

I'm writing a data import tool in sql. I'm using single and double metaphone for finding possible incorrect and duplicate data. Metaphone works fine for English like languages (French, Spanish,... ) but it doesn't work for asian languages (chinese, arabic, hindi,..). Is there any similar algorithm exists for these languages. ...

Dynamically creation copy of database for testing

Hi 2 all, I am going to create integration tests for my application. I want that my integration tests will be executed not in production DB. I want that before test execution begin, my continues integration server (team city) creates copy of my database and integration tests will be executed on it. Any approaches or best practicies ? E...

Restore DB from one server to another by sql-script

Are there any way to restore db from one server to another, if I know other server IP address? Can I do it by sql-script or some wizard? I use MS Sql Server Managment Studio 2008 ...

Is there a way to get a boolean without casting in SQL Server?

Hello, I've found it very weird that simple code like this is not valid: select * from table where field=true The alternative apparently being select * from table where field='true' Ok, guess I can live with that. For one reason or another I needed to do something like this recently: select true as somefield,... The alternative ...

SQL Server AS statement aliased column within WHERE statement

I want to execute a query in which I rename one of the columns using the 'AS' statement and reuse that aliased column name within the 'WHERE' statement. Below is an example: SELECT lat AS latitude FROM poi_table WHERE latitude < 500 The problem here is that SQL Server does not like this query because of the WHERE clause and the AS s...

How do I join on "most recent" records?

I've got two tables in a SQL Server 2000 database joined by a parent child relationship. In the child database, the unique key is made up of the parent id and the datestamp. I'm needing to do a join on these tables such that only the most recent entry for each child is joined. Can anyone give me any hints how I can go about this? ...

SQL Set Column Equal to Value

I have the following query. I need Description to be set to the value of the long statement in the middle - the part beginning with CONVERT and ending with [Description]. The query I have now runs but the value of Description in the result is always NULL. Any ideas? select s.SectionId, s.Academic_Year [AcademicYear], s.Academic...

FREETEXTTABLE always has a rank of 0

I'm using SQLServer 2008 and if I perform the following query: SELECT * FROM FREETEXTTABLE(SomeTable, Name, 'a name that I know exists') I get the rows back that I would expect, but the rank is always 0. Searching for a solution to this problem, I found this question on the Microsoft ASP.NET forum, and sure enough if I add: ALT...

Writing dynamic SQL queries

I am having problems trying to create a fairly simple dynamic SQL query. The variables don't display the values they contain when I PRINT @SQLString. Any ideas? ALTER PROCEDURE [dbo].[usp_ItemSearch] @ItemNum varchar(30) = NULL ,@SearchFilter int ,@VendorNum varchar(10) = NULL ,@RecUserID int = NULL ,@StartDate s...

What's the point to enclose select statements in a transaction?

Hi guys, What's the point to enclose select statements in a transaction? I think select statements are just "GET" data from the database, they don't have chance to rollback something, because you just can't change the data. So, does that to say we never need put select statements in a transaction? Am I right? Thanks. ...