sql

c# sql database - how to reada all specific rows from table?

Hello all, I have a SQL Table "Roles" in DB. I want to find out if user have one or more Roles (Admin/User) and then do something with a value if user have 2 Roles at time. Problem: I cant get all Values from Database, I getting just a first one. can I do it with foreach loop? I dont have it here but i'm looking for solution. like: ...

Creating Nondeterministic functions in SQL Server using RAND()

After a bit of searching and reading the documentation, it's clear that you can write user defined functions in SQL Server that are marked as either deterministic or nondeterministic depending on which built-infunctions are used within the body. RAND() is listed under the nondeterministic functions (see msdn article). So why can't I use...

If a table T1 has single column c1 with data base (a,a,b,b,b,c)

If a table T1 has single column c1 with data base (a,a,b,b,b,c) write a query that gives output as a 2 b 3 ...

Linq query for a nested select statement with grouping and distinct

I'd like to translate the following SQL statement into a linq query: select COUNT(*), itemid, globalid, title, preview, previewimage, previewimage_alt, link from ( select distinct Id, itemid, globalid, title, preview, previewimage, previewimage_alt, (select top 1 link from LikeCounter where GlobalId=x.GlobalId...

MySQL Syntax Error

I am getting this error when I try to run this MySQL command: CREATE TABLE READERWARE(TITLE VARCHAR_IGNORECASE NOT NULL, AUTHOR VARCHAR_IGNORECASE NOT NULL, ISBN CHAR, PUBLISHER VARCHAR_IGNORECASE, BOOKFORMAT CHAR, FIRST CHAR, SIGNED CHAR, PUBDATE VARCHAR_IGNORECASE, PUBPLACE VARCHAR_IGNORECASE, COPIES CHAR, RATING INTEGER, CONDITION IN...

Explain this short SQL query to me please

"SELECT * from posts A, categories B where A.active='1' AND A.category=B.CATID order by A.time_added desc limit $pagingstart, $config[items_per_page]"; I think it says selects the rows from the 'posts' table such that the active entry in each row is equal to 1 but I don't understand the rest. Please explain. Thank you. ...

T-SQL Dynamic xquery

Hi All, I am trying to figure out how I can load my table variable with data from XML using dynamic xquery? I am getting a result set of nodes from the query and defining the value type of those nodes. It seems that it is the value definition of the nodes that it is blowing up on. Here is an example of the script that works, but is ...

SQL Min(Date) issue with still getting all dates

I am trying to get only records that are the min date of the orderID I have the following setup: select op.OrderID, op.id, MIN(op.Date) AS Date From OrderPermits op GROUP BY Op.OrderId op.id, MIN(op.Date) AS Date Orders has 1 to many order permits. The problem here is that I am still getting duplicate order Id's when I only want th...

MySQL: how do I add up values if the occur on the same day?

I have a column of datetimes, and a column of values. How do I add up all teh values that occur on the same day? so like... midnight:01 to 23:5 => add all the records that occur in that time period. then group by day. bit hard to explain. sadness. ...

Crystal Reports Selection Formula

Does anyone know how/if you can use a MIN() in selection formula for a Crystal Report? Im wanting to do this: Dim sql As String = "" Dim startDate As Date = CDate(_startDate.ToString(_dateFormat)) Dim endDate As Date = CDate(_endDate.ToString(_dateFormat)) sql = "min({" & tableName & "." & dateFieldName & "}) <= " & st...

MySQL: query to sort data based on the attribute of another column.

So, coming up with a title for this is difficult SELECT Date(p.born_at), SUM(p.value) as 'total_value_for_day' FROM puppies as p WHERE p.status = 2 GROUP BY DATE(p.born_at); So, this gives a 2 column result. What I want is this: columns: date | status = 1 | status = 2 | status = 3 DATA!!! is there a way to do that? ...

MYSQL: replace null with 0?

if i get a null table cell in my results, is there a way to convert it to 0? but just for the results? not actually modifying the data? ...

DTD syntax for SQL UNIQUE constraint

Hi, I am moving from accessing data from database to xml for my application specific need. I am currently writing DTD for the xml by referring to my sql table schema. I have defined a constraint on 4 columns to be unique(These 4 columns defines a directory structure 3 step deep so together they have to be unique eg. dir1/dir2/dir3/dirA ...

sql server: is there a way to get last record inserted without stored procedure?

is there a way to get last record inserted without stored procedure in a multi-user environment? i am connected to sql server through vba. i insert some records and call: SELECT SCOPE_IDENTITY() this is not working. it is returning null every time. here is the entire code: Dim sqlstring1 As String sqlstring1 = "delete from batchin...

SQL return all id's from 1 table and only ones that don't match from another

I have 2 tables: #tmptable1 and #tmptable2. These tables have an ID to uniquely identify each record. I want to return all records from table 1, but I only want to return the records from table 2 that aren't in table 1 I want this done in 1 query. Thanks! ...

is there a way to do SELECT SCOPE_IDENTITY() in ADODB?

With rs .AddNew ' create a new record ' add values to each field in the record .Fields("datapath") = dpath .Fields("analysistime") = atime .Fields("reporttime") = rtime .Fields("lastcalib") = lcalib .Fields("analystname") = aname .Fields("reportname") = rname .Fields("batchstate") = bstate .Fields(...

MYSQL: how do I remove the first row?

The first row is my results is all null, how do I remove that from my results? This is my query: SELECT COALESCE(UNIX_TIMESTAMP(Date(p.published_at)),0) as 'day', COALESCE(SUM(case when p.status = 2 then p.value end),0) as 'total_accepted', COALESCE(SUM(case when p.status = 1 then p.value end),0) as 'total_open', ...

SCOPE_IDENTITY() vs. rs.Fields

what is the difference in the way these work: Sql = "INSERT INTO mytable (datapath, analysistime,reporttime, lastcalib,analystname,reportname,batchstate,instrument) " & _ "VALUES (dpath, atime, rtime,lcalib,aname,rname,bstate,instrument) SELECT SCOPE_IDENTITY()" Set rs = cn.Execute Set rs = rs.NextRecordset and this: With rs ...

app.config file in C# for SQL Server 2005 in VS 2008

Possible Duplicate: app.config file in C# for MS SQL Server 2005 in VS 2008 I have C# .net project with SQL Server 2008 written in Visual Studio 2008. There I used the following connection string to connect with SQL Server: string connectionString = @"server = HASIBPC\SQLEXPRESS; Integrated Security = SSPI; database = XPHote...

Sql Server - Remove End String Character "\0" From Data

I have a column in the database (SQL Server 2005) that has data with a "\0" at the end. When querying in SQL Server, this character is not visible and does not "seem" to exist. When I look in my C# code, the character is there. This character is causing an error on our website, and we need it removed from all the affected rows. Is th...