|
Thanks man
it was very easy
Thanks
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Hello,
I'd like some help on the following problem - I need to use an alias as a condition in the where clause:
select field1,
field2,
field3,
field1*field2-field3 as some_alias
from table1
where some_alias between 10 and 20
Using an alias like that returns the following error:
Invalid column name 'some_alias'.
Could anyone propose a solution?
|
|
|
|
|
Hi Dobromir,
You can use the alias definition in the where clause. Here is your query modified:
select field1,
field2,
field3,
field1*field2-field3 as some_alias
from table1
where (field1*field2-field3) between 10 and 20
Regards,
Mehroz
|
|
|
|
|
thank you for your answer, but is'n this going to cause a recalculation of the value of the alias?
|
|
|
|
|
Hello. I have the following problem:I need to retreive top(N)rows for each group in a single query. Here is an example of what I would like to do:
select top(10) with ties
table1.field1,
table1.field2,
table2.field1
from table1 inner join table2 on table1.some_field = table2.same_field
group by table1.field1
order by table1.field1
As you can see, this query will return only 10 rows. What I need is 10 rows for each group (table1.field1).
Can anyone help?
|
|
|
|
|
Try something like this:
SELECT
t1.Field1,
t1.Field2,
t2.Field3
FROM Table1 t1
JOIN Table2 t2 ON t2.JoinField = t1.JoinField
WHERE
t2.IdField IN
(
SELECT TOP(10)
t3.IdField
FROM Table2 t3
WHERE
t3.JoinField = t2.JoinField
ORDER BY
t3.IdField DESC
)
It is called a correlated subquery.
|
|
|
|
|
Hi,
Anyboby can give me real scenario example how to use indexing on the table.
Requirement:
example in MS-SQL.
Thanks
|
|
|
|
|
Please define your question better. What do you want to do, create an index (try BOL) or decide on what column(s) should be in the index?
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi,
GM
first of all thanx for replying.
mine queries are
-how to create index
-in which field it should be
-explain me this concept in example
thanks
Ashish
|
|
|
|
|
You are having a laugh aren't you? Can I collect whatever qualification is is you are trying for?
Ashish Kumar Vyas wrote: how to create index
Try BOOKS ON LINE, thats what they are for
Ashish Kumar Vyas wrote: in which field it should be
Rather dependant on the table, usage etc etc
Ashish Kumar Vyas wrote: explain me this concept in example
Where do you start? I know, google!
just to show I'm not all bad:
CREATE INDEX index_name ON table(column,column....)
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Create a Database
To create a database:
CREATE DATABASE database_name<br />
Create a Table
To create a table in a database:
CREATE TABLE table_name<br />
(<br />
column_name1 data_type,<br />
column_name2 data_type,<br />
.......<br />
)<br />
Example
This example demonstrates how you can create a table named "Person", with four columns. The column names will be "LastName", "FirstName", "Address", and "Age":
CREATE TABLE Person <br />
(<br />
LastName varchar,<br />
FirstName varchar,<br />
Address varchar,<br />
Age int<br />
)
This example demonstrates how you can specify a maximum length for some columns:
CREATE TABLE Person <br />
(<br />
LastName varchar(30),<br />
FirstName varchar,<br />
Address varchar,<br />
Age int(3) <br />
)
The data type specifies what type of data the column can hold. The table below contains the most common data types in SQL:
Data Type Description
integer(size)
int(size)
smallint(size)
tinyint(size) Hold integers only. The maximum number of digits are specified in parenthesis.
decimal(size,d)
numeric(size,d) Hold numbers with fractions. The maximum number of digits are specified in "size". The maximum number of digits to the right of the decimal is specified in "d".
char(size) Holds a fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in parenthesis.
varchar(size) Holds a variable length string (can contain letters, numbers, and special characters). The maximum size is specified in parenthesis.
date(yyyymmdd) Holds a date
Create Index
Indices are created in an existing table to locate rows more quickly and efficiently. It is possible to create an index on one or more columns of a table, and each index is given a name. The users cannot see the indexes, they are just used to speed up queries.
Note: Updating a table containing indexes takes more time than updating a table without, this is because the indexes also need an update. So, it is a good idea to create indexes only on columns that are often used for a search.
A Unique Index
Creates a unique index on a table. A unique index means that two rows cannot have the same index value.
CREATE UNIQUE INDEX index_name
ON table_name (column_name)
The "column_name" specifies the column you want indexed.
A Simple Index
Creates a simple index on a table. When the UNIQUE keyword is omitted, duplicate values are allowed.
CREATE INDEX index_name<br />
ON table_name (column_name)<br />
The "column_name" specifies the column you want indexed.
Example
This example creates a simple index, named "PersonIndex", on the LastName field of the Person table:
<br />
CREATE INDEX PersonIndex<br />
ON Person (LastName)
If you want to index the values in a column in descending order, you can add the reserved word DESC after the column name:
<br />
CREATE INDEX PersonIndex<br />
ON Person (LastName DESC)
If you want to index more than one column you can list the column names within the parentheses, separated by commas:
CREATE INDEX PersonIndex<br />
ON Person (LastName, FirstName)<br />
|
|
|
|
|
Hi
I want to create a sql query which meet following criteria but i can't understand how can i write this. I tried a lot but did not successed.
My table structure is as follow.
ATA_Question.
Qid -- Catid -- Subcatid -- SortOrder -- Question --
1 1 1 1 question.
Suppose the table contain 30 question having catid=1 and sort number varies between 1 to 9. Now i want to show the first top 12 question which having catid=1 and sort order in ascending.
If Question 30 having sort order 1 and catid=1 then my query return top 12 question which having sort order in ascending. First it show question having sort order 1 then next sort order 2 and so on and return top 12 question.
How can i write the query for this. Please help me?
I have solved that one
Regards
Rahul
People Laugh on me Because i am Different but i Laugh on them
Because they all are same.
modified on Wednesday, March 26, 2008 2:36 AM
|
|
|
|
|
rahul.net11 wrote: I have solved that one
So, have you solved your problem or not?
If you have, you should modify your post title to indicate the problem is solved and post your solution. Otherwise people will waste their time trying to help you find a solution you have already got.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
I executed the following query using Visual Basic in the Table Adapter wizard.
SELECT less_time, less_day
FROM tbl_lessons
WHERE (teach_id = 100)
AND (less_status = 1)
AND (less_time = '1/1/1900 3:00:00 PM')
AND (less_day = 2)
In visual basic I use @param1, @param2 and @param3 for the teach_id, less_time and less_day.
When I ran the query in Visual Basic I get the following error, but when I run the identical query using the SQL Server Express I do not get the error. Has anyone seen this error before? Why does it happen? How do I fix it?
Error Source: System.Data
Error Message: Failed to convert paramater value from a dateTime to a timeSpan.
|
|
|
|
|
Take a look at the parameters that you've generated in the wizard. You'll find that one of them is a TimeSpan; and the code is passing in a DateTime. That's what you need to sort out.
|
|
|
|
|
I looked in the wizard and I can't find a place to select a dataType. One of my table columns is a UDT named time that I created from dateTime. I did not create an assembly. Also the dateTime datatype that I pass in is a dateTime that adds a timespan to change the startTime.
Is it possible that the time dataType could cause this? I also increment startTime with timeSpan which is a dateTime dataType in VB.NET. Could this cause the problem?
|
|
|
|
|
Hi please can someone help me.
I've got an application that I've written in VB 2008 Express. To Install the App. I'm using Inno Setup 5.
I would like to have a direct link to the SQL Server 2005 express. So, if the Install checks and finds that the Sql Server Express is not installed then if the user clicks ok it goes direct to installation. I've found the link for .Net Framework 2.0 but no luck for SQL Server Express 2005.
Any help would be greatly appreciated.
Thanks alot
Kris MCP
|
|
|
|
|
|
Hi Dave
Gather you're a bit confused sorry about that. I need a direct link to SQLServer 2005 express.
I've tried going to the web site but when you click to download it shows the error address. They've obviously got problems.
Thanks alot
Kris MCP
|
|
|
|
|
Hi Dave
Just to let you know I've finally found the link it's "http://go.microsoft.com/fwlink/?LinkId=65212">http://go.microsoft.com/fwlink/?LinkId=65212
Took a bit of finding so if anyone ever needs it I've pasted it in.
Thanks for your help.
Kris MCP
|
|
|
|
|
Strange. All the links on those pages worked for me. I clicked on each one before I posted the message.
|
|
|
|
|
Microsoft SQL 2005
---------------------
I created a table name items.
which has to be updated with multiple rows at once, only the ID is Unique.
(more details)
SO when i updated a record there would be six rows with the same items but with different ID.
GIVEN BELOW IS A SAMPLE (6 times)
---------------------------------
ID | Name | Model| Price
---------------------------------
0001 MotorCar Mazda 62000.00
0002 MotorCar Mazda 62000.00
0003 MotorCar Mazda 62000.00
0004 MotorCar Mazda 62000.00
0005 MotorCar Mazda 62000.00
0006 MotorCar Mazda 62000.00
I guess a range(eg.1 to 15) is required to validate the number of time You may required to update a record.
Any suggestion on this would be great indeed.
thanks.
so much of happy ending...
|
|
|
|
|
Hi,
I'm trying to replace the ' character inside a varchar field with another character (such as `). For example, in the database I have a record of the form "Hello, I'm happy to meet you". I apply the REPLACE function to this record: REPLACE(<table_name>.<field_name>, '''', '`'). Theoretically, the result should be "Hello, I`m happy to meet you". But it's not. The record is not affected by the REPLACE. Does anyone know a logical explanation? Or is this voodoo? :P
Thanks
|
|
|
|
|
But you already have the correct character in the field, why replace it with an incorrect one?
Are you setting the field to the new value?
<table_name>.<field_name> = REPLACE(<table_name>.<field_name>, '''', '`')
|
|
|
|
|
Why is ` incorrect? I want to change the ' inside the varchar field because i want to generate an insert command, for example, inside a text file. If i don't change it, the command in the file would be something like this: INSERT INTO some_table VALUES (..., 'Hello, I'm happy to meet you')
And my problem is that the string ends right after "I". I also tried doubling the ' character but it didn't work that way either.
|
|
|
|