sql

SQL Server Gender Swap Query

I have a Table having the following column: ID, Name, Designation, Salary, Contact, Address, Gender Accidentally for all male Gender i have entered 'Female' and similarly for all Female gender i have entered 'Male'. For Exmaple 0023 Scott Developer 15000 4569865 Cliff_Eddington,USA Female I the above line There should be Male inste...

SQL Server: query database user roles for all databases in server

I would like to make a query for database user roles for all databases in my sql server instance. I modified a query from sp_helpuser: select u.name ,case when (r.principal_id is null) then 'public' else r.name end ,l.default_database_name ,u.default_schema_name ,u.principal_id from sys.database_principa...

How to use a variable to specify filegroup in SQL Server

I want to alter a table to add a constraint during upgrade on a SQL Server database. This table is normally indexed on a filegroup called 'MY_INDEX' - but may also be on a database without this filegroup. In this case I want the indexing to be done on the 'PRIMARY' filegroup. I tried the following code to achieve this: DECLARE @fgName...

MySQL Module for Python

What is a good, and easy to install MySQL module for Python? Especially for Mac OS X (in terms of installation)? ...

Are there any limits on length of string in mysql?

I am using mysql data base with rails. I have created a field of type of string. Are there any limits to its length? What about type text? Also as text is variable sized , I believe there would be extra costs associated with using text objects . How important can they get , if at all ? ...

ASP error 424 Object required

I've got a problem with the following code pasted below, the problem seems to be coming from the openastextstream this carries on from another question: Set str_text_stream = obj_file.OpenAsTextStream(ForReading, TristateUseDefault) response.Write "<table>" int_j = 0 int_x = 0 Err.number = 0 Do While Not str_text_stream.AtEndOfStream ...

SQL: Search and Replace part of string in all tables

Is it possible to search and replace all occurrences of a string in all tables of a database? ...

Recommended book for SQL Server query optimisation

Even if I have made a certification exam on SQL Server Design and implementation, I have no clue about how to trace/debug/optimise performance in SQL Server. Now the database I built is really business critical, and getting big, so it is time for me to dig into optimisation, specially regarding when/where to add indexes. Can you re...

how to pass variables this in dynamic query in sql

i using the dynamic query to pass the variables select a.TableName, COUNT(a.columnvalue) as '+'count'+' from Settings a where a.ColumnValue in ('+ @columnvalue +') and a.Value in (' + @value +') the @columnvalues = 'a','b','c' @value ='comm(,)','con(:)' how to pass this in dynamic query any idea??? ...

Find records IN BETWEEN Date Range

Please see attached image I have a table which have FromDate and ToDate. FromDate is start of some event and ToDate is end of that event. I need to find a record if search criteria is in between range of dates. e.g. If a record has FromDate 2010/15/5 and ToDate 2010/15/25 and my criteria is FromDate 2010/5/18 and ToDate is 2010/5/21...

mysql showing null values for group by statements

I'm doing: select sum(clicks), date from stats group by date ...however when the sum is null for some date, the whole row is discarded, I want to see: | null | some_date |, how to do so? ...

Difference between Inner Join & Full join

What is the difference between a full join and an inner join? When I do a full join I get 832 records and with an inner join I get 830 records. ...

Will hibernate java programs have no sql code?

I haven't worked with hibernate. I have little bit of experience in java. I was going through source of a beast of an java application created by Oracle(Retail Price Management). I was expecting a lot of sql code embedded in there as the application makes heavy use of database. But to my surprise, NO embedded SQL code! so far. I found th...

Which is faster in SQL, While loop, Recursive Stored proc, or Cursor?

Which is faster in SQL, While loop, Recursive Stored proc, or Cursor? I want to optimize the performance in a couple of spots in a stored procedure. The code I'm optimizing formats some strings for output to a file. ...

What is a good practice for handling SQL connections within a WCF call?

Suppose I want to create a (stateless) WCF service with three methods exposed on an endpoint: performSqlOperationA(), performSqlOperationB(), and performSqlOperationC(). Each method inserts data into a SQL database. The way I've seen things done at my office, each method would begin with code to initialize a SqlConnection object. Each...

Is it possible to backup HTML5 websql database?

I'm thinking of developing an iPhone app using HTML5 because I don't have mac and not planning to own one, so learning Objective-C would be pointless. The other reason why I want to use HTML5 is because it's a cross-platform (albeit it depends on the browser). Anyway, I know you can use WebSQL in HTML5 to store offline data, but is it p...

Why use shorter VARCHAR(n) fields?

It is frequently advised to choose database field sizes to be as narrow as possible. I am wondering to what degree this applies to SQL Server 2005 VARCHAR columns: Storing 10-letter English words in a VARCHAR(255) field will not take up more storage than in a VARCHAR(10) field. Are there other reasons to restrict the size of VARCHAR fie...

How can I fill SQL Server table from excel only using sql query?

How can I do that with Microsoft.ACE.OLEDB.12.0? CREATE TABLE [dbo].[Addresses_Temp] ( [FirstName] VARCHAR(20), [LastName] VARCHAR(20), [Address] VARCHAR(50), [City] VARCHAR(30), [State] VARCHAR(2), [ZIP] VARCHAR(10) ) GO INSERT INTO [dbo].[Address_Temp] ( [FirstName], [La...

alter mysqldump file before import

Hi-- I have a mysqldump file created from an earlier version of a product that can't be imported into a new version of the product, since the db structure has changed slightly (mainly altering a column that was NOT NULL DEFAULT 0 to UNIQUE KEY DEFAULT NULL). If I just import the old dump file, it will error out since the column that ...

Fine tune some SQL called multiple times

Hi all, I currently have an SQL query which is currently called multiple times like this (pseudo code): foreach(KeyValuePair kvp in someMapList) { select col1 from table where col2 = kvp.key and col3 = kvp.value; //do some processing on the returned value } The above could obviously call the database a large number of times if...