|
Something like this:
SELECT
CompanyName,
SUM(CASE WHEN [Year] = 1997 THEN [Total Sales] ELSE 0 END) AS [1997],
SUM(CASE WHEN [Year] = 1998 THEN [Total Sales] ELSE 0 END) AS [1998]
FROM MyTable
GROUP BY CompanyName
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
Thanks Colin Angus Mackay for help me about query
|
|
|
|
|
Hi,
I'm a little confused with the ORDER BY statement....
It seems I can't use a renamed column to sort using ORDER BY.
Eg:
SELECT LastName + ', ' + FirstName AS FullName FROM Suppliers ORDER BY FullName"// this gives an error
but if I have a UNION ALL statement, I do need to use the renamed column to sort:
SELECT LastName + ', ' + FirstName AS FullName FROM Suppliers WHERE LogNumber IS NULL UNION ALL SELECT LogNumber + ' - ' + LastName + ', ' + FirstName AS FullName FROM Suppliers WHERE LogNumber IS NOT NULL ORDER BY FullName"// this works
I realize that I can use ORDER BY LastName,FirstName in the first example, but I just wonder if I should be doing something different.
thanks,
Ron
|
|
|
|
|
The reason is that FullName is not one of the column names in any of the tables. Your solution of using ORDER BY LastName, FirstName would be the one I'd use.
As for the UNION ed SELECT statments, I didn't realise that would happen - I'd have automatically used ORDER BY LastName, FirstName for that too. However, it does make sense in a way - If you look at the execution plan for the query, the FullName column does exist before the output ordering process as all the SELECT s get UNION ed together first.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
|
Hi,
I'm working with a Win Form and MS Access.
How can I update a field that is a LongInteger to NULL after it has been set with a value? Yes, the db column is set to accept null.
This of course did not work )
myCommand.Parameters.Add("@Number", OleDbType.BigInt).Value = null;
Thanks,
Ron
|
|
|
|
|
try this
myCommand.Parameters.Add("@Number", OleDbType.BigInt).Value = "";
dadax_85@hotmail.com
|
|
|
|
|
That won't work either. An empty string is not null , it is a string of zero length.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
Instead of null , use System.DBNull.Value . This is because in certain cases you will need to distinguish between a C# null and a database null. For example, in the case of ExecuteScalar a null result means that there was no result (i.e. the answer did not exist) whereas if ExecuteScalar returns DBNull.Value then the answer from the database is null (i.e. there is an answer, and the answer is null).
See MSDN: System.DBNull[^]
Does this help?
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
I tip my hat to you Colin, thanks!!!
I have another issue with changing the field to DBNull...
but I think this is a C# issue with binding textbox with DataTable
and so I'll post it there as well.
I'm not able to:
if (txb_Number.Text == "")
{
//this never occurs because the textbox reverts to the original bound Long Integer value
}
I can only change the bound data if a new number is used. A blank textbox (or letters entered) only reverts back to the origninal value. I want to update the field to DBNull if the textbox is empty.
Ron
|
|
|
|
|
Hi Ron,
Please try the following
myCommand.Parameters.Add("@Number", OleDbType.BigInt).Value = DBNull.Value
or
myCommand.Parameters.Add("@Number", DBNull.Value)
|
|
|
|
|
i need to import inside a sql server 2005 table a file exel
with a column with some strings.
column
-------
sfsdfsfd
dsfsfgg
54432fd
dss43r
gdgdgdfgd43
gdfgdfg43
etc...
how can i do?
|
|
|
|
|
Use DTS
Look where you want to go not where you don't want to crash.
Bikers Bible
|
|
|
|
|
|
DTS : Data Transformance Services
Used to import export information by SQL server in Packages that can be run as timed or scheduled events.
Look where you want to go not where you don't want to crash.
Bikers Bible
|
|
|
|
|
Frank Kerrigan wrote: DTS : Data Transformance Services
DTS was renamed SSIS (SQL Server Integration Services) in SQL Server 2005 - It didn't happen until the after the first beta went out so the development team decided not to rename all the classes - So the namespace for programatically accessing SSIS still refers to DTS or DataTransformationServices.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
Trying to create a report with tabular format. Run into a few problems...
I have the following entities:
a. Project (Parent of Budget and Contract)
b. Budgets
c. Contracts
So, I created two dataset:
<br />
SELECT <br />
PRJ.[ID] AS PROJID, <br />
PRJ.[Name] AS PROJNAME, <br />
PRJ.[CreateDate] AS PROJCREATEDATE, <br />
CTR.[ID] AS CONTRACTID, <br />
CTR.[Code] AS CONTRACTCODE, <br />
CTR.[Name] AS CONTRACTNAME<br />
FROM <br />
Project AS PRJ INNER JOIN<br />
Contract CTR <br />
ON PRJ.[ID] = CTR.[ProjectID]<br />
<br />
-- DataSet - ProjectBudget: <br />
SELECT <br />
PRJ.[ID] AS PROJID, PRJ.[Name] AS PROJNAME, <br />
PRJ.[CreateDate] AS PROJCREATEDATE, <br />
BDG.[BudgetType] AS BUDTYPE,<br />
BDG.[BudgetDescMM] AS BUDDESCMM,<br />
BDG.[BudgetDescYYYY] AS BUDDESCYYYY,<br />
BDG.[Remarks] AS BDGREMARKS<br />
FROM <br />
Project AS PRJ INNER JOIN<br />
Budget BDG<br />
ON PRJ.[ID] = BDG.[ProjectID]
Now, in my report, I have this ONE table - I wish to have "Project ID" as first column of this table, with TWO drilldown buttons (the "+" sign/button) buttons to respectively show/hide child "Budget" and child "Contract". The problem is, Reporting Service allow one to specify only ONE dataset for each "Table" on the report (right click table, then: "Properties>General>Dataset Name" - only one dataset can be selected.).
I tried to get around this by using "hyperlink" navigation instead of drilldown buttons. But, anyone can tell me if any security issue will get into the way when user navigate from one report to another through embedded hyperlink? Will user be prompted to enter credential twice?
Thanks in advance!
|
|
|
|
|
Hi All
I have a table I would like to sort by name but found that Upper Case and Lower Case of the same character is not treated the same.
SELECT *
FROM MyTABLE
ORDER BY [NAME]
Are the characters being treated as ASCII Code please help....
When people make you see red, be thankful your not colour blind.
|
|
|
|
|
japel wrote: Are the characters being treated as ASCII Code
If the database Collation sequence is set to Latin1_General_BIN then yes, the characters are ordered in the binary sequence of character set.
If it isn't then I would guess that the collation sequence in use is case sensitive.
The default option on installation is Latin1_General_CI_AS (Case insensitive, Accent sensitive) so I would imagine that who ever installed SQL Server had a good reason for changing the default setting.
You can, however, use ORDER BY UPPER([NAME])
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
-- modified at 10:20 Sunday 23rd April, 2006
|
|
|
|
|
Hi
Can any bodu tell me what is the Difference between Equi join, self Join and innner join?
Any help is appreciated
Regards
Rajesh
|
|
|
|
|
Equi-join is where two tables are joined on a column (or columns) with matching values.
A self-join is where a table joins onto itself.
An inner-join is where the join condition must match on both sides - The most common sort of inner join is an equi-join.
To complete the list:
An outer-join will match rows for both sides of the join where it can, and substitute nulls where it can't.
A cross-join will join every row one side to every row on the other side of the join (For a large table this is a very expensive operation).
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
I was creating the stored procedure in SQL Server and durind that I stuck into an error
The Query is
Create Procedure Procedurename
@names varchar;
@roll int;
as
Insert into tablename values(@names , @roll)
pankaj garg
|
|
|
|
|
You should post your actual code because this may not be representative.
The error in your example code is that you need to use commas when separating parameters into the stored procedure
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
hey
Create Procedure Procedurename
(
@names varchar,
@roll int
)
as
Insert into tablename values(@names , @roll)
dadax_85@hotmail.com
|
|
|
|
|
what is the difference between these in performance considerations?
1:
SqlParameter paramArticleID = new SqlParameter ( "@articleID" , SqlDbType.Int );
paramArticleID.Value = articleID;
sqlCommand.Parameters.Add ( paramArticleID );
2:
sqlCommand.Parameters.Add ( "@articleID", articleID );
|
|
|
|
|