|
Michael
Thanks for help with my select query. I now have one that does extactly what's required thanks to you and Colin.
Best regards
Steve Jowett
-------------------------
Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'
|
|
|
|
|
What is the data type for NULL ? I heard that NULL is untyped. But some article's say it's character type. If it is character type, then what about NULL value contained in a numeric column ?
Other article say's NULL's data type is the data type of the column which it belongs to ?
Which is correct ? Any ideas ?
|
|
|
|
|
NULL does not have a type. It can be used as a non-value in a column of any datatype, where that column's definition allows nulls. It is implemented (in SQL Server at least) as an additional bit per nullable column within the row so it doesn't restrict the range of values that can be represented.
In the .NET Framework, NULL's type is DBNull .
Do be aware that different databases implement NULL differently, and not all are completely SQL-92 conformant.
DoEvents : Generating unexpected recursion since 1991
|
|
|
|
|
Mike Dimmick wrote: It is implemented (in SQL Server at least) as an additional bit per nullable column within the row so it doesn't restrict the range of values that can be represented.
I am not cleared on this. Can you please explain it more ?
|
|
|
|
|
It is just an internal storage requirement. Nothing for anyone writing SQL to actually worry about. How NULLs are represented internally has no effect on your SQL statements.
|
|
|
|
|
Colin Angus Mackay wrote: How NULLs are represented internally has no effect on your SQL statements.
Yes I know. But yesterday we had a discussion on the datatype of null. My friend was arguing it is character type. So I just want to confirm it
|
|
|
|
|
Say that a column is defined as having the smallint datatype. This is a 2-byte integer. The documentation says it can hold values from -32,768 to 32,767. This is the range of a signed 16-bit value. If SQL Server were to hold the NULL as a special value, one value would have to be reserved for that purpose, restricting the range of values you could store.
Instead, each row carries an internal, hidden field called the nullable bitmap. This field is big enough to hold the null value bits for each nullable column in the table, rounded up to a whole number of bytes. If there are 8 or fewer nullable columns, 1 byte will be used, if 9 to 16 nullable columns, 2 bytes, if 17 to 24, 3 bytes, and so on. If the column is set to NULL, SQL Server sets the appropriate bit in the nullable bitmap; if set to an actual value, the corresponding bit is cleared. If this bit is set when reading the record, the value in the field itself is disregarded.
The full details of how SQL Server actually stores data can be found in "Inside SQL Server" by Kalen Delaney (for 2005, "Inside SQL Server 2005: The Storage Engine").
Personally I prefer to avoid NULLs where possible. It can get very confusing differentiating NULLs that are the actual column (non-)value and those that arise from outer joins where no match was found.
DoEvents : Generating unexpected recursion since 1991
|
|
|
|
|
Thanks Mike. It helped a lot. thanks again
|
|
|
|
|
A null entry denotes the absence of an entry, so you could say that a NULL has no data type because it doesn't make sense to have a type for something that isn't there. I know that this seems a bit esoteric, so bear with me.
How many values can a boolean have? Now, while you may argue that a boolean can only have two values (true or false), you can also have the absence of the value - i.e. null. This doesn't mean that the data type for a null is a boolean here.
So, to answer your question, the NULL item has no type.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
That was perfect. So will oracle also consider in the same way ?
|
|
|
|
|
All standard databases will consider the NULL to be an absence of a value, i.e. without type.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi,
I would like to create a query that display the data on a transactional level with the related dimension on each row. I can acheive this using the DRILLTROUGH but it doesn't seem right as this is a top-level query and not a drill-trough.
My query is
DRILLTHROUGH MAXROWS 100 Select ([Measures].[ID])
on 0 From [NBOS]
RETURN [Fact Trade].[ID] AS LiveTradeID,[Fact Trade].[Volume],
[Fact Trade].[Total Volume],[Fact Trade].[Price],
[Fact Trade].[Commission],[Fact Trade].[Commission2],
[Fact Trade].[Trade Count],[$Company].[Company],[$Counterparty].[Company],
[$Instrument].[Instrument Name],
[$Sequence Item].[Sequence Item],[$Date Time].[Full Date Alternate Key]
I looking for something similar to this SQL
SELECT * FROM FactTrade
INNER JOIN Instrument ON Instrument.InstrumentID = FactTrade.InstrumentID
Does anyone know the best practice to do this.
THANKS SO MUCH IN ADVANCE
|
|
|
|
|
Hi all
I'm trying to write a DTS that as it's first step checks a log table as to whether the process has already run for that date, and if it has, exit.
I thought I'd be able to have an 'Execute SQL Task' with something like the following:
DECLARE @ContributionDate DATETIME
DECLARE @NoOfRecords INT
SET @ContributionDate = GetDate()
CREATE TABLE #Results(NoOfRecords INT)
INSERT INTO #Results EXEC db.dbo.vsDissemination_HasRun @ContributionDate, 'C'
SET @NoOfRecords = (SELECT TOP 1 NoOfRecords FROM #Results)
DROP TABLE #Results
IF @NoOfRecords > 0
BEGIN
RAISERROR('Dissemination has occurred',1,1)
END
ELSE
SELECT 1
Which when the error was raised would go down the On Failure branch, but it always goes to the On Success branch.
Running the script in Query Analyzer does either return a numeric value or an error.
Firstly, is this the best way to do this check?
If it is, why doesn't it work - if not, how should I be doing this?
Thanks
Ben
|
|
|
|
|
Try RAISERROR('Dissemination has occurred',16,1) .
|
|
|
|
|
Thanks Andy -
The error is now being thrown (if I run the package in the designer) but it doesn't go to the On Failure step - is that expected?
Ben
|
|
|
|
|
dbo.Members got some column mID, mfName, mlName, mJoinDate, mExpiredDate
dbo.MemberStatus got some column mID, mStatus
Now I want to create a function which will be automatically check Mebers.mExpiredDate and update the value into MemberStatus.mStatus
IF mExpiredDate > today Then
memberStatus.status = true
Else
memberStatus.mStatus = False
End IF
Could please tell me how will I create this function into my database.
Sarfarj Ahmed
|
|
|
|
|
Assuming that you use MS SQL Server:
<code>Update dbo.MemberStatus
Set status = Case when dbo.Members.mExpiredDate > getdate() then 1 Else 0 End
From dbo.Members join dbo.MemberStatus On dbo.Members.mID=dbo.MemberStatus.mID</code>
|
|
|
|
|
Thanks
Im using sql server 2005.
could you please tell me where should i keep this function? inside TableValued, Scalar .....
Sarfarj Ahmed
|
|
|
|
|
Thanks
Im learning ASP.NET and SQL SERVER 2005
If i put the code (you given me) inside my ASP.NET QueryString then I can execute this command. But I want this code inside my SQL SERVER 2005, So when someone Logon then it will cecck the the Status from MemberStatus.
Please tell me what should I do? Thanks again for your Help.
Sarfarj Ahmed
|
|
|
|
|
Hello, I was hoping someone could help me with an error I recieve during program execution. Code below with explanation below that. Codes in C# with Access backend.
public partial class Form1 : Form
{
public string conString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\..\\testdatabase.mdb";
public OleDbConnection con;
public OleDbDataAdapter dAdapter;
public DataSet dSet;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
con = new OleDbConnection(conString);
dAdapter = new OleDbDataAdapter("SELECT * FROM agent WHERE firstname = '" + textBox1.Text + "'", con);
dSet = new DataSet();
dAdapter.Fill(dSet);
DataTable datatable = dSet.Tables[0];
if (datatable.Rows.Count != 0)
{
textBox1.Text = (string)datatable.Rows[0][1];
textBox2.Text = (string)datatable.Rows[0][2];
}
}
I was running a test and noticed that , for instance, if my sql inquiry where modified to search the ID field in my database
SELECT * FROM agent WHERE agentid = '" + textBox1.Text + "'",
and when I enter a number into textbox1 say the number 1 , I get an error thrown in .net at the line below
dAdapter.Fill(dSet);
Which in short says "datatype mismatch" - I am successfully able to do SQL select inquiries with strings typed into the textbox but not numbers.
Also, the test database has 1 table with around 5 fields.
As spelled
( agentid, firstname,lastname,username,password)
1 bob jenkins bjenkins 1234
2 john willows jwillows 4321
I test the program by entering 1 into textbox1.
For the life of me I can't figure it out and do not have much experience.
Thanks in advance.
|
|
|
|
|
I think you don't need to enclose agentid in ' so your query should look like this:
SELECT * FROM agent WHERE agentid = textBox1.Text
Also, your query is prone to sql injection attacks. For more information about it and preventing them have a look at this article:
SQL Injection Attacks and Some Tips on How to Prevent Them[^]
|
|
|
|
|
Awesome!
Thanks for the information. I will read up on it later.
|
|
|
|
|
You are welcome
|
|
|
|
|
If you are attempting to filter a resultset by applying a WHERE condition to a numeric field, you shouldn't surround the filter value with quotes.
Paul Marfleet
|
|
|
|
|
hi ,
thank you all for your time .
currently im working on a project which involve oracle database there for my application insist of oracle client 8.7 or higher to be installed on the end user machine in order to work.
i need an advice for a light oracle client , untill now i was testing the application with oracle client 9i ,it works great , but the problem is that this client is about 600mb while compressed and arround 1gb after installation , my customers are concerned about it , since its a small application , why does it need such a huge oracle client in order to work?
so my question is , if you know of some "smaller" oracle client that applications like that can run with?
thnks again.
Net
|
|
|
|