sql

How do I do this query with ActiveRecord Class from Code Igniter?

I need to increment the number of comments on an Entries Table, the SQL for this would be: UPDATE entries SET comments = comments + 1 WHERE entry_id = 123; And i was wondering how to do this using Active Record Class form Code Igniter. http://codeigniter.com/user_guide/database/active_record.html#update ...

LDAP vs SQL database for user authentication/user data storage

Hello SO, I am starting to use cakePHP for the first time with a hobby project. It looks like cakePHP supports LDAP easily enough as well as any DB. If the project goes well, I am thinking of letting the general public use the site, which means that there will (potentially) be a lot of users (a lot is relative, I guess, I'd be shocked...

How to use LIKE clause with IN caluse in Sql Server?

I want to use LIKE clause and IN clause together. e.g: Currently my query is - SELECT * FROM [USER_DETAILS] WHERE [NAME] LIKE 'Dev%' OR [NAME] LIKE 'Deb%' OR ...... ...... How can i use IN clause to achieve this? Can someone please help? :) ...

MySQL Correlated Subqueries: Subquery cant find table from outer query?

its been sometime since i used corelated subqueries, i am not sure if i am doing this right. in my subquery 2nd last line, i am trying to get node.id from the outer table. when i try executing the query, i get Error Code: 1054 Unknown column 'node.id' in 'where clause') select node.id, node.title, depthLookup.depth from posts no...

Searching with words one character long (MySQL)

I have a table Books in my MySQL database which has the columns Title (varchar(255)) and Edition (varchar(20)). Example values for these are "Introduction to Microeconomics" and "4". I want to let users search for Books based on Title and Edition. So, for example they could enter "Microeconomics 4" and it would get the proper result. My...

SQL Server date error

I try to execute the query below but I got an error saying"The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.". I try to convert the date and cast the date but same error will comes out. select DATEDIFF(YEAR,cast(Startdate as datetime),isnull(cast(Enddate as datetime), GETDATE())) fro...

MySqlDataReader stops reading after about 4 minutes and returns

I have a simple query which returns 25,026 rows: MySqlCommand cmd = new MySqlCommand("SELECT ID FROM People", DB); MySqlDataReader reader = cmd.ExecuteReader(); (ID is an int.) If I just do this: int i = 0; while (reader.Read()) i++; i will equal 25026. However, I need to do some processing on each ID in my loop; each iteration e...

How to make table dynamic in sql

Does anyone know how to write a script in stored proc to run the table based on the variable (or will it possible to do so?)? for example: I have 3 tables name called customer, supplier, and support when user input 1, then run table customer, 2 table supplier and 3 table support declare @input int; if @input =1 begin declare @table ...

SQL Script - Check if a IP has been black listed

Hi, I am studing SQL, and I would like your advice, to see if my code is written properly, or better way to do it. This script create: a table to store IPs address that are Black Listed a sproc to allow spitting an IP address in 4 octet a SPROC that allow to check if a IP is Black Listed or not Please let me know! thanks! -- Black Lis...

sql query from 3 tables

dear i need to get query from 3 tables i try to show how i need result in picture hope this will explain every thing. ...

How to drop clustered property but retain primary key in a table. SQL Server 2005

i have the following key: ALTER TABLE dbo.Table ADD CONSTRAINT PK_ID PRIMARY KEY CLUSTERED ( ID ASC ) so i have clustered index and primary key on ID column. Now i need to drop clustered index (i want to create new clustered index on another column), but retain primary key. Is it possible? ...

Count using like in SQL - how to?

I got a two tables tblGoals -name -url -siteID tblUrlCollection -url -siteID How do I count how many times every "url" from tblGoals is in tblUrlCollection using "url" and "siteID" as input? Would like to use like or something so I can add wildcards to the end of the "url" input parameter. Please help me out - thanks a lot. Perfor...

using isDBNULL to store null back in the database

Hi, I have many TextBOX in asp.net which accepts the value from user and stores it to SQL DB through SQL SERVER.. When the user does not enter the value in the textbox, Which means i can allow the null for that filed in the table, But if its integer variable it stores 0, thats because int HostelFees ; HostelFees = TextBox1.Text; //fu...

how to insert current date and time to db using sql

hi, I used the following code, but the DateTime field at sql is 2005-04-08 00:00:00 I want to have the time too. where should i change ... ... // Get the system date and time. java.util.Date utilDate = new Date(); // Convert it to java.sql.Date java.sql.Date date = new java.sql.Date(utilDate.getTime()); ... ... ... PreparedStatement ...

Is it faster to check if length = 0 than to compare it to an empty string?

I've heard that in some programming languages it is faster to check if the length of a string is 0, than to check if the content is "". Is this also true for T-SQL? Sample: SELECT user_id FROM users WHERE LEN(user_email) = 0 vs. SELECT user_id FROM users WHERE user_email = '' ...

How to view the last ran sql query from SqlClient data provider on Sql server 2000 ?

Although I have been able to see the last ran query which is a Stored Procedure executed but I didn't get the parameters values with which the SP was invoked. Rather I got the following: StoredProcedureName;1 from the following command: DBCC INPUTBUFFER(SPID) Where I got the SPID by viewing it in the ObjectExplorer->Management->Act...

How to write a Sql statement without using union?

Hi, I have a sql statement like below. How can I add a single row(code = 0, desc = 1) to result of this sql statement without using union keyword? thanks. select code, desc from material where material.ExpireDate ='2010/07/23' ...

Variable not getting set by select

I have an issue where a variable is not getting set by a select statement. The select joins a table variable @contracts (which is used to control a loop) and then joins to the real contract and contract line tables. my select is: select top 1 @contract_id = c.contract_id , @account = ch.account , @service = c...

SQL Server joins and where statements not working

I have this SQL Server statement, and I am not sure why it is returning no records: SELECT contacts.firstname , contacts.lastname , contacts.address1 , contacts.city, contacts.zip, countries.title AS countrytitle, states.title AS statetitle FROM providers, payableinvoices, contacts LEFT JOIN countrie...

Inserting a resultset into a Table in Oracle

Heyho, I've gotta write a Procedure which Inserts a resultset from a select-statement into a table. A co-worker of mine did something similar before to copy values from one table to another. His statement looks like this: CREATE OR REPLACE PROCEDURE Co-Worker( pId IN INT ) AS BEGIN INSERT INTO Table1_PROCESSED SELECT * FROM...