sql

How to get value instead of fieldname in Unpivot query

Hi This is my query Declare @SampleUNPivot Table(ID int ,Name varchar(50),a int,b int,c int,d int) insert into @SampleUNPivot values(1,'name1',1,2,3,4) insert into @SampleUNPivot values(2,'name2',10,20,30,40) insert into @SampleUNPivot values(3,'name3',11,21,31,41) insert into @SampleUNPivot values(4,'name4',14,24,34,44) Select ID,Na...

Drop database only if Backup is successful

Hi, This might be an easy one for some one but I haven't found a simple solution yet. I'm automating a larger process at the moment, and one step is to back up then drop the database, before recreating it from scratch. I've got a script that will do the back up and drop as follows: Use [Master] BACKUP DATABASE [databaseName] TO DI...

XML declaration with "FOR XML PATH" in SQL Server 2005

Below is a simplified version of a query that I have already created. The query works fine, but I cannot figure out how to get the XML declaration at the top of the generated XML. I've tried multiple things and searched far and wide on the Google, but alas I cannot seem to find out how to do this ... or even if it is possible. select ...

equivalent of SQL binary relative value test in C#

I am trying to figure out the equivalent C# for this SQL: @var1 = "1a1" @var2 = "1F" CONVERT(varbinary, @var1) > CONVERT(varbinary, @var2) Is it the same as this? if (var1.CompareTo(var2) > 0) { } If not, then how do I simulate it? ...

Java: Writing SQL Statements

I'm writing a one-time Java program to add a bunch of rows in a CSV file to a MySQL database. Are there any Java classes/toolkits to help with this? Something that will escape necessary characters, etc? (eg prepared statements) Or should I just write the statements myself, like this: result += String.format( "INSERT INTO node (type,...

Java: Connect to SQL on Apache locally

I have a site running a Linux/Apache/MySQL/PHP stack. I would like to connect to the database from a locally run Java program. Is this possible? (Deploying the Java program to the server would be a great effort.) ...

sql query disregarding all rows that have all null columns

I have an SQL Server query that needs to count the number of rows returned, but I need to disregard rows where all the column values are NULL. Some rows have NULL values for some of the columns, but that is ok. I just need to filter out the ones that have ALL NULL values. Right now I am returning all rows and using a SqlDataReader itera...

MySQL syntax for Join Update

I have two tables that look like this Train +----------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+-------------+------+-----+---------+-------+ | TrainID | varchar(11) | NO | PRI | NULL | | | Capacity | int(11) | NO | | 50 | | +-...

Is there a XSD schema for SQL Select statement

I have a SQL SELECT Statement: SELECT Code, Description FROM Table1 WHERE (Code='a' and Amount>100) or (Code='b' and Amount<100) I wish to use XML to present the SELECT statement. Here is my initial design: <select table="Table1"> <columns> <column name="Code"/> <column name="Description"/> </columns> ...

How to Execute stored procedure from SQL Plus?

I have a stored procedure in oracle and want to test it from SQLPlus. If I use execute my_stored_proc (-1,2,0.01) I get this error PLS-00306: wrong number or types of arguments in call to my_stored_proc The beginning for the proc is this create or replace PROCEDURE my_stored_proc ( a IN NUMBER, b IN NUMBER, c IN NUMBER, ...

SQL [Conversion to bool]

C++Builder ADOQuery SQLServer I'm using a stored procedure with this select SELECT Name, COALESCE( ( SELECT TOP 1 0 FROM TbUserParam WHERE TbUserParam.ID_User = @ID_User AND TbUserParam.ID_Param = CfgListParIzm.ID_ListParIzm ), 1) Visi FROM CfgListParIzm WHERE ...

VCL SQL [Query parameters error]

C++Builder ADOQuery SQLServer Continue of This questions line using this select with procedure : SELECT C.Hint, CAST(CASE WHEN T2.ID_Param IS NULL THEN 1 ELSE 0 END as bit) AS Visi FROM CfgListParIzm C LEFT JOIN ( SELECT T.ID_Param FROM TbUserParam T WHERE T.ID_User = @ID_Use...

SQL Server - Better Data type to store large string value

we have a database table which has around 200,000 records. which includes 3 ntext columns, which hold string data with length vary from 4000-70000. but a mere selection on the table takes more than 1 minute to return data. and even using where condition, and indexes to select 12000 records for a condition it takes 40 sec. so we decided...

Getting unused unique values on a SQL table

I've got a table which have a column describing a numeric ID, which is unique for all the rows (but it's not the primary key). The numeric ID are limited (let's say for the answer that can be from 1 up to 10) SELECT ID FROM TABLE; ID --- 1 2 5 I've got to present to the user (via a UI) the unused values to let choosing a correct...

Anybody care to explain "Tokenized Field" in terms of Databases?

I am reading about SOLR and indexing a MySQL database into SOLR. What do they mean by "tokenize" and "un-tokenize"? And what does it mean when fields are "normalized"? I know how and what it means to normalize a database, but a field? How can a simple field be normalized? Thanks ...

SQL calculation (Oracle)

I have two db tables Fine and Fine_payment. Fine has fields * fine_id[pk] * fine_amount. Fine_payment has fields * fine_payment_id[pk] * fine_id * payment_amount So every Fine can have multiple payments. How would I go about selecting those Fines that haven't been paid fully and show the unpaid amount? Oracle DB. ...

Reading a text file

hi friends i am importing a text file database in my sql server database in asp.net c#. but i cannot fetch the column name from .txt file which contains a numeric data now what to do? please tell me if anyone knows very very thanx in advance ...

Execution Plan reuse

Consider the following "code" define stmt1 = 'insert into T(a, b) values(1, 1); define stmt2 = 'select * from T'; MSSqlCommand.Execute( stmt1;stmt2 ); MSSqlCommand.Execute( stmt2 ); Investigating the cached query-plans using: SELECT [cp].[refcounts] , [cp].[usecounts] , [cp].[objtype] , [st].[dbid] , [st].[objectid] , [st].[tex...

SQL WHERE clause for column all capitalized

table_beatles contains the following data in column name. John PAUL george RINGO In MS-SQL is there anyway to get any item which is all caps? eg SELECT * FROM table_beatles where name is (AllCaps SYNTAX HERE) to return PAUL and RINGO. ...

Should I use Primary key here?

As an example, I have a 3 tables: School: ID int, Name varchar Student: ID int, Name varchar StudentInSchool: StudentID int, SchoolID int Now the question is whether I should put a column ID int with a primary key on it in StudentInSchool table? If yes, why? Will it be helpful in indexing? Any help appreciated. ...