sql

Advanced (?) AND / OR query

For quite a simple table structure, ie. Person, Criteria, and PersonCriteria (the combi-table), I have set up a query at the moment that selects all persons that possess all selected criteria. The query itself looks like this at the moment: SELECT p.PersonID FROM Person p, ( SELECT DISTINCT PersonID, CriteriaID ...

What's the way to check others servers IIS status from asp.net page?

I need to check every five minutes if 4 servers are online from one asp.net page running in a fifth server, in order to redirect requests and send alert by e-mail to the network manager. Specifically I need to know if IIS is running ok in those servers. What's the best way to do it? Is there any component or socket library to use in orde...

Calculating the closest future periodic payment date in SQL

I'm working on an application that deals with periodic payments Payments are done fortnightly i.e. payment 1: 2009-06-01 payment 2: 2009-06-15 payment 3: 2009-06-29 and now I need a SQL statement that can calculate the closest next payment date from a given date in the WHERE clause i.e. SELECT ... FROM ... WHERE someDate < [CALCUL...

fetch from function returning a ref cursor to record

I have a function in a package that returns a REF CURSOR to a RECORD. I am trying to call this function from a code block. The calling code looks like this: declare a_record package_name.record_name; cursor c_symbols is select package_name.function_name('argument') from dual; begin open c_symbols; loop ...

How to implement a conditional Upsert stored procedure?

I'm trying to implement your basic UPSERT functionality, but with a twist: sometimes I don't want to actually update an existing row. Essentially I'm trying to synchronize some data between different repositories, and an Upsert function seemed like the way to go. So based largely on Sam Saffron's answer to this question, as well as som...

Calculating number of full months between two dates in SQL

I need to calculate the number of FULL month in SQL, i.e. 2009-04-16 to 2009-05-15 => 0 full month 2009-04-16 to 2009-05-16 => 1 full month 2009-04-16 to 2009-06-16 => 2 full months I tried to use DATEDIFF, i.e. SELECT DATEDIFF(MONTH, '2009-04-16', '2009-05-15') but instead of giving me full months between the two date, it gives m...

Condensing this code

I have the following code I want to run, but the problem is $this->type is set when the class is created by specifying either petition, proposal, or amendment. As you can see my $sql statement is a UNION of all three, and I want to specify which table (pet,prop,or amend) each row of data comes from. public function userProposals() { ...

Sybase ASE: "Your server command encountered a deadlock situation"

Hello, When running a stored procedure (from a .NET application) that does an INSERT and an UPDATE, I sometimes (but not that often, really) and randomly get this error: ERROR [40001] [DataDirect][ODBC Sybase Wire Protocol driver][SQL Server]Your server command (family id #0, process id #46) encountered a deadlock situation. Please ...

SQL Statement that never returns same row twice?

Requirements: I have a table of several thousand questions. Users can view these multiple choice questions and then answer them. Once a question is answered, it should not be shown to the same user again even if he logs in after a while. Question How would I go about doing this efficiently? Would Bloom Filters work? ...

How do database naming conventions change for multitenant applications?

For multitenant databases, to you name tables differently based on: Whether the table will host multiple tenants or just rely on the exist of a tenant column If you support multiple "applications" such as salesforce.com, do you prefix the application name to the table? Do you try to keep the names the same across tables where it may no...

can i reuse a C# SqlParameter

i am doing a continuously select every 10seconds, so i thought i would do some premature optimsing and save creating a cmd and paramater objects in everyloop if i do this in one method public void FirstSelect() { // select data this.cmdSelectData = new SqlCommand(SQL_SELECT_DATA, conn); this.paramBranchId = new SqlParame...

Performant techniques for finding similar values in SQL?

So I've got a column in a table that contains a string values (keywords populated from a 3rd party tool). I'm working on an automated tool to identify clusters of similar values that could probably be normalized to a single value. For example, "Firemen"/"Fireman", "Isotope"/"Asotope" or "Canine"/"Canines". An approach that calculates th...

How to avoid OOM (Out of memory) error when retrieving all records from huge table?

Hi all, I am given a task to convert a huge table to custom XML file. I will be using Java for this job. If I simply issue a "SELECT * FROM customer", it may return huge amount of data that eventually causing OOM. I wonder, is there a way i can process the record immediately once it become available, and remove the record from memory a...

Aggregating two selects with a group by in SQL is really slow.

I am currently working with a query in in MSSQL that looks like: SELECT ... FROM (SELECT ... )T1 JOIN (SELECT ... )T2 GROUP BY ... The inner selects are relatively fast, but the outer select aggregates the inner selects and takes an incredibly long time to execute, often timing out. Removing the group by makes it run somewhat...

E mail id storing

how we can store the e mail id into a database? i mean which datatype is used for storing e mail id's. ...

Using parameterized SQL with LIKE in WHERE clause (Pervasive SQL)

Hi all, I have a Pervasive database that I connect to using C++. All my queries so far is parameterized, i.e "SELECT USER.NAME FROM USER WHERE USER.ID = ?", and that works fine. But in a search query I use LIKE in the WHERE clause, and then it seems I can't use parameters and wild chars (%). My query looks something like this "SELECT ...

Difference between using from list and left join.

I have two database tables with the following structure: actions: action_id int(11) primary key action_name varchar(255) action_module varchar(45) permissions: perm_id int(11) primary key perm_role int(11) perm_action int(11) perm_status int(11) Now I have to check whether there is an entry in the permission...

Database Relationship

I have two database one with relationship(no data) and another with out Relationship (with data) and i want to insert data from one database to another database i am not able import data i got the error for forgien key. Is there any way for this ? ...

How to use LIKE condition in SQL with numeric field?

Hi, I'm using this query to get some specific data: "select * from emp where emp_name LIKE 's%'"; emp_nam is character field, how can I use the same logic condition with numeric field? something like: "select * from emp where emp_id ???? where emp_id is numeric field. Thanks, ...

MySql User Defined Variable

How to use the user defined variable in a way that the value of the variable is reused in the subsequent query in mysql? ...