|
You need to give the column an alias.
e.g.
SELECT 1 * 2 AS total FROM tablename
|
|
|
|
|
|
I know. I assumed he wanted to name his column because of the = Result in his example and was trying to indicate that he could achieve this by using an alias. Perhaps I read more into the example than was required.
I think it is good practice to name your calculated columns as it makes your commands easier to read and understand.
|
|
|
|
|
|
Colin is correct. You don't have to provide an alias in order to get the product of the two columns. I assumed that you were trying to name your column because of the = Result in your example. If that is not what you were trying to do I hope I didn't confuse you.
|
|
|
|
|
SUBJECT: Criteria query - Parent's property as select criteria.
Hi, I'm trying to issue a SELECT statement via Criteria query, but can't get it working...
<br />
Basically, I have two classes:<br />
<br />
Public Class MyChildClass<br />
...<br />
Public Property MyParent As MyParentClass<br />
...<br />
End Property<br />
<br />
Public Property ChildProp1 As Int32<br />
...<br />
End Property<br />
...<br />
End Class<br />
<br />
Public Class MyParentClass<br />
...<br />
Public Property ParentProp1 As Int32<br />
...<br />
End Property<br />
...<br />
End Class<br />
Now, ...
<br />
criteria = BIS_session.CreateCriteria(GetType(MyChildClass))<br />
criteria.Add(Expression.EqExpression.Eq("ChildProp1 ", SomeValue))<br />
OKAY, so far so good. BUT, what do I do to do this...:
<br />
criteria.Add(Expression.EqExpression.Eq("MyParent.ParentProp1", SomeValue))<br />
Can you do table joins with "Criteria Queries"? I checked Hibernate's documentation... , wasn't able to locate information I needed.
Thanks in advance.
Norman Fung
|
|
|
|
|
Caveat: I'm still learning nHibernate and I'm using Session.Find() instead of criteria.
What I had to do was use the unique value of the parent when searching for the child. Here's how I'm using it.
I have a class Employee, which contains a property Position (also a Hibernate class). In the database, Position is referenced through Employee.PositionID. When searching for all the Employees in a chosen Position, I do...
<br />
Position posToSearchFor = service.FindPositionByName("Test Position");<br />
session.Find("from Employee where PositionID = ?", posToSearchFor.ID.ToString(), NHibernate.Type.TypeFactory.GetStringType());<br />
|
|
|
|
|
Thanks Martin. I think I could do with HQL. But, I have already written a bunch of things in the method using Query Criteria - try to stick with it. But, is this a limitation of Query Criteria?
Norman Fung
|
|
|
|
|
Hello Friends,
Recently I came one problem, when i opened Sql Enterprise Manager, on right side of window list of Tables, there when i right click on table and i am getting total number of rows say 5 but when i double click then here i am getting 12 rows!!!!!!!!!!!!!!
How That possible?????
I checked through Query Analyser also there also i am getting 5 rows!!!
Can Any body know this
Please Help me out!!!!!!!!!
Thanks In Advance
Shashank
|
|
|
|
|
|
Hello Colin Angus Mackay,
When I right click on table i am getting menus there open table>> Return all rows
here i am getting 5 rows while when i double click on table_name there i am getting 12 rows!!!
how that is possible?????
Thanks In Advance
Shashank
|
|
|
|
|
|
under2811 wrote:
how that is possible?????
It's impossible.
<italic>Work hard, Work effectively.
|
|
|
|
|
Yulianto. wrote:
It's impossible.
Actually, it isn't. I've seen the database report in Enterprise Manager so many rows for a table, but if I do a SELECT COUNT(*) FROM TableName in the Query Analyser I get a different result. This is because the database statistics haven't been rebuilt recently so some parts of the database are operating on out of date information. This does not affect the results of a query (it will always be accurate based on the current state of the database) however, out of date statistics can slow down the database as the query optimiser may choose an incorrect query plan.
My: Blog | Photos
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
I see. Never notice it. Thank you for the info.
<italic>Work hard, Work effectively.
|
|
|
|
|
Any way Thanks A Lot!!!!!!!
|
|
|
|
|
We have an app made in C# which promtes users for a sql query at run time, this has become difficult for the users but we were thinking of an easy to use query builder to integrate & instead of writing from scratch we were were wondering if there were available tools to use ??
|
|
|
|
|
I do not know of a query-builder per se, but at one time we had to generate reports where the functionality would be similar to what you want to do. But like you said, it is difficult for users to write full blown queries, and not only that but you could also run into security problems...
The solution we came up was using templates (SQL Server 2000)...where we had multiple queries defined and users would click on the the most appropriate report type, enter some parameters and bingo, get a report back. A template might look like this:
<?xml version="1.0"?>
<data xmlns:sql='urn:schemas-microsoft-com:xml-sql'>
<sql:header>
<sql:param name="fieldid">0000</sql:param>>
</sql:header>
<sql:query>
Select CustomerName 'name' From dbo.Customer where gender = @fieldid for xml raw
</sql:query>
</data>
This would return the data in xml format (dat as root) - which can be routed through xslt to output nicely formatted result (text/html etc).
This is just an idea - I am sure there are other options out there. This worked well for us as we had more control over every aspect and we could add more "reports" as needed by users. Let me know if you want to pursue this option and I'll point you into the right direction.
|
|
|
|
|
what do u about SQL-DMO is there any possibility to use the functionality?
|
|
|
|
|
Sorry, never used it.
...think concepts, teach to learn...
|
|
|
|
|
i have a database in access, and need information from one table, to be displayed based on textbox value. I have tried repeatedly, and just cant get it. Here is the problem all help greatly appriciated.
database: upsdb.mdb
table: calpackage
columns: sm_trackingno, sm_referencetext0
I am trying to pull the referencetext0 and display as a label with the following:
select sm_referencetext0, sm_trackingno from calpackage where sm_trackingno = txttrack.text
label.text=sm_referencetext0
TIA
|
|
|
|
|
I hope that's pseudo code.
SqlCommand cmd = new SqlCommand("SELECT sm_referencetext0 FROM calpackage WHERE sm_trackingno = @trackingNo", myConnection);
string result = cmd.ExecuteScalar();
label.Text = result; The above code assumed you already have a connection called myConnection and it is open.
Does this help?
My: Blog | Photos
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
Colin's answer was more or less correct. Since you are using Access, you need to use the OleDb * classes.
using(OleDbConnection conn = new OleDbConnection(connString))
{
OleDbCommand cmd = new OleDbCommand("SELECT sm_referencetext0 FROM calpackage WHERE sm_trakingno = ?", conn);
cmd.Parameters.Add("param1", txttrack.Text);
label.Text = (string) cmd.ExecuteScalar();
} For the connection string for your database, check http://www.connectionstrings.com[^], but it should look something like this:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User Id=admin; Password=;"
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Hello friends!!!!!!!!!!!!!
I expand "Management"
then I expand "Current Activity"
then I expand "Locks / Object"
in the tree on the left side (not the opened window) I see a list of
databases and the objects in each database currently with a lock placed on it.
Most of the listings in this tree are something like:
Northwind.dbo.Categories
but what I'm seeing for one particular database is something like this:
Northwind.jdoe.Categories
Normally I make all objects owned by dbo, however I have some systems that
require another user to be the object owner. such example. However the owner of all the objects is not this "jdoe", but
let's say "jsmith". In which case I would expect the tree listing the
objects being locked to look like this:
Northwind.jsmith.Categories
NOT
Northwind.jdoe.Categories
especially, as I stated previously, since jdoe is just a valid user in
the db.
So, I'm still confused..
How could I remove this jdeo????????????????????
I will remove him by sp_changedbowner.
but why and how that 'jdoe' comes in picture!!!!!!!!!!
Is there any perticular command or login type work because of
that 'jdoe's' name came into picture?????????????????
Help Me Out!!!!!!!!!!!!!!!!
Regards
shashank
|
|
|
|
|
Hi,
I'm a newbie in this but I what to make a VB.NET application that adds a jpg picture to row in a SQL Server 2000 database.
Thanks in advance.
Dino Sousa
|
|
|
|