sql

SQL LIKE query failing - fatal error in prepared statement

I have the following code: $countQuery = "SELECT ARTICLE_NO FROM ? WHERE upper(ARTICLE_NAME) LIKE '% ? %'"; if ($numRecords = $con->prepare($countQuery)) { $numRecords->bind_param("ss", $table, $brand); $numRecords->execute(); $data = $con->query($countQuery) or die(print_r($con->error)); $rowcount = mysql_num_rows($data...

SQL Select where values in List<string>

Is there a way that I can create query against a data source (could be sql, oracle or access) that has a where clause that points to an ArrayList or List? example: Select * from Table where RecordID in (RecordIDList) I've seen some ways to do it with Linq, but I'd rather not resort to it if it's avoidable. ...

Programmatically detect SQL Server Edition

I'm using C# with SMO and attempting to detect what edition of SQL Server (e.g., enterprise, standard) I'm connecting to. I know how to get the version information, but that only tells me what version of SQL Server (e.g., SQL Server 2008 vs SQL Server 2005). Does anyone know how to get the actual product edition (e.g., enterprise, stan...

"infinite" sql statement?

Hi there, I've got a very strange sql-related problem. I'm accessing a MSSQL Server 2005 with PHP (odbc), when I profile the sql statement the following is executed: declare @p1 int set @p1=180150003 declare @p3 int set @p3=2 declare @p4 int set @p4=1 declare @p5 int set @p5=-1 exec sp_cursoropen @p1 output,N'SELECT fieldA, fieldB,...

SELECT DISTINCT in DataView's RowFilter

I'm trying to narrow down the rows that are in my DataView based on a relation with another table, and the RowFilter I'm using is as follows; dv = new DataView(myDS.myTable, "id IN (SELECT DISTINCT parentID FROM myOtherTable)", "name asc", DataViewRowState.CurrentRows); "myTable" and "myOther" table are related...

How can I implement a boolean tag search in SQL?

Given a table of items, a table of tags and a join table between them, what is a good and efficient way to implement queries of the form: p1 AND p2 AND ... AND pn AND NOT n1 AND NOT n2 ... AND NOT nk I am using SQL. So to find all items that match all tags p1...pn and none of n1...nk? Is there a good "standard" solution for this? ...

Is there a way to import SQL script into MDF database in Visual Studio?

I created a "Service-Based Database" (.MDF) in Visual Studio and now want to import a SQL script into it, but cannot find any way to do this: I can right-click on the .mdf file and choose "New Query" but there is no place to copy in query text as in Management Studio Does the Visual Studio 2008 Database Explorer have a way to enter o...

SQL set column names from another query

I'm am using MS Reporting Services to graph some data from an Oracle database. I want to name the columns in my select statement with values from another select statement. Is this possible? Like instead of "Select Column1 As 'Test' From Table1" could I do something like "Select Column1 As (Select column2 from Table2 where Value = 1) Fro...

Left Outer Join and Exists in Linq To SQL C# .NET 3.5

I'm stuck on translating a left outer join from LINQToSQL that returns unique parent rows. I have 2 tables (Project, Project_Notes, and it's a 1-many relationship linked by Project_ID). I am doing a keyword search on multiple columns on the 2 table and I only want to return the unique projects if a column in Project_Notes contains a key...

BIRT 2.2 dynamic schema name

Is it possible to make the schema name dynamic in a BIRT query. I tried this: SELECT CURRENT DATE AS DATE, (CASE WHEN DAYOFWEEK(CURRENT DATE) = 1 THEN 'SUNDAY' WHEN DAYOFWEEK(CURRENT DATE) = 2 THEN 'MONDAY' WHEN DAYOFWEEK(CURRENT DATE) = 3 THEN 'TUESDAY' WHEN DAYOFWEEK(CURRENT DATE) = 4 THEN 'WEDNESDAY' WHEN DA...

I need the highest ID from database. Am I doing this right?

set qv = createobject("adodb.recordset") q ="select * from tbl order by ID" qv.open q,QuoteConn,3,1,1 qv.movelast qid=qv("ID") qv.close EDIT: awwww, y'all killed the joke. In year 2009, I am maintaining this piece of code... ...

How to implement LIMIT with Microsoft SQL Server?

I have this query with mysql : select * from table1 LIMIT 10,20 How can I do this with Microsoft sql ? ...

How do I join tables on an update

I have the following query: select count(L.ID) from LA inner join L on (LA.leadid = L.ID) where L.status = 5 and L.city = "cityname" and Date(LA.Datetime) < Date_Sub(Now(), INTERVAL 6 MONTH); which looks for records with status 5 in a particular city that are older than 6 months (the date for which is...

ADO.net without writing SQL (esp. WHERE)

I have this idea that using SQL VIEWS to abstract simple database computations (such as a count on a relation) is sufficient, and you don't need procedures (== procedural code) A simple sql view + a where clause >> a stored procedure with parameters sometimes While making this point I imagined a way of retrieving table/view data withou...

SQL Query joins

Hi, I have a table called tblIssueTicket tblIssueTicket contains the fields: TicketID, TicketRequesterID, ApprovalManagerID, RequestDate, ApprovalDate, TicketStatus There is another table called tblEmployeeProfile. tblEmployeeProfile contains fields EmployeeID, EmployeeFirstName, EmployeeLastName I need to display the following records...

How can I learn SQL Server index tuning?

What is the best practical way of learning index tuning while writing tsql queries? I have VS2008 SQL Express. Could someone please provide me examples, etc? I have already found online articles and they are great in theory, but I still fail to see index tuning in real life action. Are there small easy to create examples out there? ...

concat selected values in a single result row, can it be done (without grouping)?

I have the following structure: main: id | meta_data sub: main_id | another_table_id main is connected to sub in a one to many. I wish to get back my result as one record which will look like: [main_id] [meta_data] [another_table_id,another_table_id,another_table_id] Is it possible in MySql without using GROUP BY? ...

distinct sql query

I have a simple table with just name and email called name_email. I am trying to fetch data out of it so that: If two rows have the same name, but one has an email which is ending with ‘@yahoo.com’ and the other has a different email, then the one with the ‘@yahoo.com’ email should be discarded. what would be best way to get this dat...

rrd tool alternative for high volume

I am interested in knowing if there is any alternative to rrdtool for logging time series data. I am looking at something that can scale for a large number of devices to monitor. From what I read on this subject, rrdtool is I/O bound when you hit it with large amounts of data. Since I envision this to scale to a very large number of dev...

TSQL - How to use a case statement for 2 columns?

I want to do a case on the result of 2 columns. How do I do this? e.g.: SELECT CASE amount=100 AND DATE IS NOT NULL WHEN 0 THEN 'Something' ELSE '' Something like that? ...