|
The Case construct I am referring to is like this:
Case {expression}
{result 1} : {code block}
{result 2} : {code block}
{result 3} : {code block}
{result 4} : {code block}
Else {code block}
End Case
I would like to do something like this in tSQL on SQL Server 2000. Rather than using daisy chained If statements.
Any ideas?
Jason Jystad
Cito Technologies
www.citotech.net
Sonork ID 11.9918
>-------------------------------------------------<
Every program has at least one bug and can be shortened by at least one instruction -- from which, by induction, one can deduce that every program can be reduced to one instruction that doesn't work.
>-------------------------------------------------<
|
|
|
|
|
|
Thanks!
You are correct, I do not have access to the BOL from where I am. Thanks for the site, I was looking for something like that online, but I wasn't having much luck.
Jason Jystad
Cito Technologies
www.citotech.net
Sonork ID 100.9918
>-------------------------------------------------<
Every program has at least one bug and can be shortened by at least one instruction -- from which, by induction, one can deduce that every program can be reduced to one instruction that doesn't work.
>-------------------------------------------------<
|
|
|
|
|
|
YES...
Like this
Select
CASE FieldNumber
WHEN 0 THEN "Cero"
WHEN 1 THEN "One"
.
.
.
WHEN 9 THEN "nine"
ELSE "No Value"
END
From
MyTable
Best Regards
Carlos Antollini.
|
|
|
|
|
Yes, you are correct, it is a lot eaiser to write a Case statement than a nested if statement, especially inside those small stored procedure window of SQL Server 2000.
(CASE WHEN Cust_Name = 1 THEN 'Good Customer' ELSE 'BAD Customer' END)
or you can do nested Case statements such as:
(CASE WHEN Cust_Name = 1 then 'Good Customer' ELSE(CASE WHEN Cust_Name = 2 THEN 'SO-SO Customer' ELSE 'Bad Customer' END) END)
Hope this helps.
Nick Parker
|
|
|
|
|
In my application I first connect to SQL server using MFC ODBC classes,
then the same thread tries to to create ADO Connection object
and it fails. What's strange is that if my application first connects to MSAccess using MFC ODBC classes then it can create ADO just fine.
What's the deal with SQL ODBC drivers and ADO?
|
|
|
|
|
Make sure you have loaded the Ole Libraries
I think in MFC you need to call AfxOLEInit or something like that.
ADO will only work if you load this
|
|
|
|
|
Hi,
I'm trying to change the value of a recordset's property. The property is "scroll backwards" (want to change from false to true).
I opened a recordset, and then I got it's properties. I got the wanted property(according to it's index), but I can't change the value - I get an error saying that "the operation can't be done when the object is open".
Which object is the error talking about?
Do I need to change the property after openning the recordset?
What am I doing wrong?
Can someone please send me a code example of what should I do...???
Thanks.
|
|
|
|
|
Take a look at your CursorType if is forward only it might be the source of your problem.
|
|
|
|
|
HI.
I´m developing a database application using ado and, although it´s a large program i don´t want to use more than 2 or 3 open connections.
The problem is that i can´t define a global connection pointer, right now, i can only make it work creating a new con in every cpp file.
I´ve tryed defining a global pointer in every way i know but I´m allways getting memory or even weirder errors.
Can anyone help me out?
Pedro Besteiro
LSI systems integration
Pedro Besteiro
LSI systems integration
|
|
|
|
|
Just define pointer at connection in any your class (as class member) and set it everytime when constructing class.
|
|
|
|
|
I am trying to design a table which encompasses a Parent-Child relationship.
I essentially have three classes of data that can be stored in this table. The Level 1 items are the parents of Level 2s and Level2s are parents of Level 3s.
I was wondering what is the more recommended approach to dealing with these situations? What constraint enforcement mechanism is deemed better? Would it be better to use triggers or should i used some form of a foreign key on the same table?
|
|
|
|
|
I am using SQL 7.0 with MDAC 5.0. One of the stored procedure has a Select statement followed by Insert statement.
If the Insert statement fails due to any reason I cannot get the error in ADO Error collection object. But strangely if I put the insert first and then the select, the ADO error collection is filled ?
What is wrong or What am I doing wrong ?
Thanks
|
|
|
|
|
Just as the title!!!!!!
Thanks in advance!
Please pardon my weak English!
|
|
|
|
|
You can try using something like this:
<br />
#pragma warning(push)<br />
#pragma warning(disable: 4146)<br />
#import "\program files\common files\system\ado\msado25.tlb" rename("EOF", "adoEOF")<br />
#pragma warning(pop)<br />
then you can call ADO directly using smart pointers (e.g., ADODB::_RecordsetPtr). It's not MFC dependant.
See more info in MSDN on how to do this.
Furor fit laesa saepius patientia
|
|
|
|
|
Have an application that is targetted for both SQL Server 7 and 2000 and MSDE.
Is there a known problem with the Transaction log within MSDE that prevents it from shrinking ? I'm calling various things like DBCC SHRINKFILE through Query Analyser but it often doesn't have any effect.
Net result is that my transaction log keeps growing and growing - not something to ship to customers.
Does anyone know of a dirty way around this problem ?
|
|
|
|
|
I'm not totally sure this will work with MSDE, but its worth a shot.
Try backing up the transaction log. When you backup the transaction log, the transaction log automatically get truncated. Truncating the log just gets rid of log entries that have been commited to the database, you will not lose any active transactions. Then try DBCC SHRINKFILE to physically shrink the file.
Andy Gaskell, MCSD
|
|
|
|
|
Thanks for the idea. We'd actually tried that out and it works fine in SQL2000 but not on MSDE. Now fairly convinced that it is a problem with the MSDE implementation as we can see that before the SHRINKFILE command the log is only 7% used.
Another idea that someone gave us was to send some NULLOPs to the DB as a way of moving the active transactions around and then trying to shrink it.
We've just downloaded the SQL2000 Desktop edition which seems to respond to shrink requests and if that works, we'll use that and throw out the older MSDE installation.
I'd still be interested to know whether this is a bug in MSDE, a feature of MSDE by design to encourage you to distribute SQL2000.
|
|
|
|
|
Looking at the Numeric Datatype I see the following attributes by default.
Length 9
Precision 18
Scale 0
I know Scale is the number of decimal places but what to Length and Precision mean? The actual size of the Datatype is 8 bytes so Length doesn't seems to number of bytes.
Inside SQL Server and Online Help, haven't helped. Does anybody know the answer and where I can find this sort of information for other datatypes?
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
"Don't belong. Never join. Think for yourself. Peace"
- Victor Stone
|
|
|
|
|
It's easy to answer all your questions. To preserve some space here, I'll just tell you where can you find those informations - in the SQL Server Books Online. Search on the index tab for the 'length of data type' and you'll get all the informations you're asking for.
Best regards, Sasa
|
|
|
|
|
Hi!
I'am using ADO 2.6 with the Microsoft OLE DB Provider for Jet 4.0 driver to programmatically check the nullability of a field with the ADO Field "Attributes" property. On Win9x and WinNT(SP6) my program worked OK, but on Win2K(SP2) this property returns True even if the field is a required (non-nullable) field. Where is the problem?
Thanks,
Florin
|
|
|
|
|
Hello
I use "RecordSet.Requery()" function in VC++ to get Records of access database, it works properly but when I use it with MS SQL 6.5 database I havn't goten any record, for the same condition and identical tables.
Any help
Best Regards
|
|
|
|
|
Hello again
I am so sorry if i bother any body, I found the error, it was in the table contents.
Best Regards
|
|
|
|
|
Hi all,
I have been testing the connection pooling in ADO 2.6, and seems to work fine. By changing the OLE DB Services parameter I have seen how the pooling is enabled or disabled, in this way:
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Command1_Click()
Dim start, finish, duration As Long
Dim conn, conn2, conn3, conn4 As ADODB.Connection
Dim strConn
strConn = "Provider=SQLOLEDB.1;Persist Security Info=False;Data Source=ALBERT;Initial Catalog=MyCatalog;User ID=arichart;Trusted_Connection=Yes;OLE DB Services = -2;"
'Conn1
start = GetTickCount()
Set conn = New ADODB.Connection
conn.ConnectionString = strConn
conn.CursorLocation = adUseClient
conn.Open
finish = GetTickCount()
duration = finish - start
Debug.Print "Duration 1: " & Str(duration)
conn.Close
Set conn = Nothing
'Conn2
start = GetTickCount()
Set conn2 = New ADODB.Connection
conn2.ConnectionString = strConn
conn2.CursorLocation = adUseClient
conn2.Open
finish = GetTickCount()
duration = finish - start
Debug.Print "Duration 2: " & Str(duration)
conn2.Close
Set conn2 = Nothing
I have two more connection objects in the code I have tested (omitted here to simplify).
Ok. Perfect. The problem is that I have tested it again in Visual C++ and does not work. If I set the OLE DB Services to -1 (or 0), then pooling is enabled, and if I set it to -2, then pooling is disabled. Do you know why does it work in different ways in Visual C++ and Visual Basic?
The code in Visual C++ looks like this. I use a wrapper class to encapsulate the ADODB::_ConnectionPtr object:
CADOConnection Conn;
CString strConn = _T("Provider=SQLOLEDB.1;Persist Security Info=False;Data Source=ALBERT;Initial Catalog=MyCatalog;User ID=arichart;Trusted_Connection=Yes;OLE DB Services = -2;");
Conn.SetConnectionString(strConn);
Conn.Connect();
The connect function looks like this:
bool CADOConnection::Connect()
{
ASSERT ( m_pADOConnection == NULL );
if ( m_pADOConnection != NULL )
Close(false);
#ifdef _DEBUG
clock_t start, finish;
start = clock();
#endif
HRESULT hr = S_OK;
try {
TESTHR(m_pADOConnection.CreateInstance(_T("ADODB.Connection")));
m_pADOConnection->ConnectionString = m_strConnectionString.AllocSysString();
m_pADOConnection->CursorLocation = ADODB::adUseClient;
TESTHR(m_pADOConnection->Open("", "", "",ADODB::adConnectUnspecified));
} catch ( _com_error &e ) {
CString strError = e.Description().copy();
AfxMessageBox(strError);
m_pADOConnection = NULL;
return false;
}
#ifdef _DEBUG
finish = clock();
double duration = (double)(finish - start) / CLOCKS_PER_SEC;
TRACE("ADO Connection opened. Duration: %2.3f seconds\n", duration );
#endif
return true;
}
I'm working on Windows 2000
I hope anybody could answer my question. Thanks in advance.
|
|
|
|