|
Shahil,
The 'order by' will do the sorting in alphabetical order, since now OrderDate is a string, so I'll get 'June' before 'May'.
I need to be able to still sort by date.
thanx
|
|
|
|
|
okay,
I think I found a way around this: add a dummy column and sort by that
select cast(OrderDate as char(11)), SUM(Qty),
convert(datetime,convert(char(10),OrderDate,101))
from Orders
where convert(datetime,convert(char(10),OrderDate,101)) between '05/29/05' and '06/10/05'
group by cast(OrderDate as char(11)), convert(datetime,convert(char(10),OrderDate,101))
order by convert(datetime,convert(char(10),OrderDate,101))
|
|
|
|
|
Hi kozu
try this:
create table #tmp
(
OrderDate datetime,
qty int
)
insert into #tmp(orderdate, qty)
select OrderDate, sum(qty)
from orders
where OrderDate between '05/29/80' and '06/10/05'
group by OrderDate
order by OrderDate
select CAST(OrderDate as varchar(11)) as OrderDate, Qty
from #tmp
DROP TABLE #tmp
Shahil
|
|
|
|
|
Form your result set then use it as the source for the final query where you can format your data.
SELECT
CONVERT(VARCHAR(20),OrderDate,101) AS OrderDate,
TotalQty
FROM
(
SELECT
CAST(CONVERT(VARCHAR(20),OrderDate,101) AS DATETIME) AS OrderDate,
SUM(Qty) AS TotalQty
FROM
Orders
WHERE
CAST(CONVERT(VARCHAR(20),OrderDate,101) AS DATETIME) between '05/29/05' and '06/10/05'
GROUP BY
CAST(CONVERT(VARCHAR(20),OrderDate,101) AS DATETIME)
) AS subqry
ORDER BY
OrderDate
Speed wise, I think kubben is correct. I would remove the CAST/CONVERT in the WHERE clause of the subquery with a little intelligent manipulation of the date ranges.
|
|
|
|
|
Hi guys
I'm working in Visual studio on a website and using ADO.NET to connect to my pubs sql-database. I keep on getting error messages when I test the website in my browser. Is there anyone who can tell me what could be wrong - I've been through all the configurations steps e.g setting the remote connections... at least I think so...
I've gotten error messages like "login failure" and "The user is not associated with a trusted SQL Server connection" what might be wrong???????????
The strange thing is that if I chooe e.g. a gridview from the toolbox there is no problem at all for this autogenerated gridview to connect to the server - how can this be? - I've tried to use the autogenerated connection string from the toolbox gridview, but that doesn't seem to help...
her is some connection string that I have tried out
string CONN_STRING = "Server=.\\SQLEXPRESS;Initial Catalog=pubs;Integrated Security=SSPI";
or
string CONN_STRING = "Server=.\\SQLEXPRESS;Initial Catalog=pubs;uid=sa;pwd=";
please someone help me...
All the best
Al
|
|
|
|
|
ComCoderCsharp wrote: how can this be?
Because Visual Studio is running in your account. The web application is running in the ASPNET account - You have to tell SQL Server about this by adding ASPNET as a windows authenticated login and giving it permission to use the appropriate database.
|
|
|
|
|
Hi thanks for the reply
Maybe this could be the solution.. but it leads me to another question: How do I add windows authenticated login and give permission to the appropriate database, I can't seem to figure it out...sorry if this is a stupid question, I'm kind of new to configuring the database connections...
Thanks in advance
Al
|
|
|
|
|
In SQL Server 2000 use the Enterprise manage. In the security tab for the server you can add the log in. In the users tab for the individual database you can then set up access to the database and the objects it contains.
In SQL Server 2005 there will be a similar mechanism in the SQL Server Management Studio.
|
|
|
|
|
Hi,
I need to check if a field exists in a certain table (in an SQL database), and if not then add that field to the table.
For Instance I have Table "A" that should contain field "a". So I want to check if field a is already defined for the table, and if not then add it.
How can I d o this? Is there an SQL statement to check if a field exists?
Thanks
|
|
|
|
|
SWDevil wrote: Is there an SQL statement to check if a field exists?
IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'MyTableName' AND COLUMN_NAME = 'MyColumnName')
BEGIN
ALTER TABLE ....
END
|
|
|
|
|
If I need to add more than one fields can I write than one ALTER statements:
IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'MyTableName' AND COLUMN_NAME = 'MyColumnName')
BEGIN
ALTER TABLE ....
ALTER TABLE ...
ALTER TABLE ...
ALTER TABLE ...
END
|
|
|
|
|
You can write as many ALTER TABLE statements as you like. Or you can put it all in one ALTER TABLE statement. It is up to you.
|
|
|
|
|
I have a single table with many phone numbers per person, i.e. person data is repeated for each phone number for that person. I while ago I normalised this using SQL updates, but I can't remember how I did it and maybe here someone can give me a better way anyway. The original table has no PK, and my first step is to get all unique person data, using distinct, into a new Person table. I then want to extract phone number columns from each record, and add a column to tell which phone record belongs to which Person record.
My problem is, using distinct to get unique Person data precludes including any ID unique to a Phone record, and I have to real columns that I can use to pair new Person records with Person records in the source table except comparing all columns, and some are null, so this is out. Any suggestions?
|
|
|
|
|
I would add a new column to the existing table and update it with the primary key you created based off it matching to your new table. So your primary key would be duplicated in the old table, but that will allow you to link properly when creating your phone table.
Hope that helps.
Ben
|
|
|
|
|
My problem is matching records in the new and old tables! I have to basically compare all fields from the old table to corresponding fields in the new table, and in T-SQL comparisons don't work with null values. So, I have to, just for one field, for example:
and (new.IDNumber = old.IDNumber) or (new.IDNumber is null and old.IDNumber is null)
etc.
etc.
<edit>
I've just been made privy to the trick of using isnull() on all the field comparisons.
"A little learning is a dangerous thing; drink deep, or taste not the Pierian spring: there shallow draughts intoxicate the brain, and drinking largely sobers us again.", by Alexander Pope
My Blog
|
|
|
|
|
Well, if you are able to write a distinct select statement to create the new table to create a primary key, then you can use those same columns to update the existing table with the primary key. I don't know if you have many other choices.
Ben
|
|
|
|
|
I didn't, so thanks. With your suggestion and Excel to generate the comparison lists, it wasn't too bad.
|
|
|
|
|
Hi
My Department is Using SQl for the Database, and i have run some selected column and data into the table, and i want to have it on a CD as Backup so i can give it to other Company that uses SQl , for our calculation based on our Business. i have a SQl Query, that is ready
How can i see to it that the data is copied to the Cd and will be views in SQl on the other Company
Thanks
Vuyiswa
|
|
|
|
|
Save it as a backup file, burn the file to CD and have the other company restore the file from the CD.
|
|
|
|
|
I need the Steps on how to do it
thanks
Vuyiswa
|
|
|
|
|
Step 1: Take a backup of your database
Step 2: Copy the .BAK file to the CD
Step 3: Send the CD to the appropriate person
Step 4: Get the appropriate person to RESTORE from the BAK file.
|
|
|
|
|
|
Hi all,
I have a table with 50 rows
I need to split the resoults of the select to pages.
page 1 will have the 1st 15 rows
page 2 will have the 2nd 15 rows
page 3 will have the 3rd 15 rows
page 4 will have the remaining 5 rows
is there a query that can make my life easy
somthing like
SPLIT_IT ( [page_num], [rows_in_page], SELECT * from myTable)
thanks
|
|
|
|
|
you can use a datagrid........or a grid like control...
yes it is possible to split your record in a stored procedure...
Tirtha
Do not go where the path may lead, go instead where there is no path and leave a trail.
Author: Ralph Waldo Emerson (1803-82), American writer, philosopher, poet, essayist
|
|
|
|
|
SqlDataAdapter.Fill(DataSet, Start, TotalRows, TableName)
"The callee (server [not server application]) is not available and disappeared; all connections are invalid.
The call did not execute," said Internet Explorer, when I tried to access a deceased [window] object using JavaScript.
::..:.:..:: KiRtAN GoR ::..:.:..::
|
|
|
|