|
Hi,
Try this
SELECT DISTINCT d.Date1 as `ActionDate`, (SELECT MIN(ID) FROM dates WHERE Date1 = `ActionDate`) as `Start`, (SELECT MAX(ID) FROM dates WHERE Date1 = `ActionDate`) as `End` FROM dates d;
Happy Coding
<edit>This assumes table is called dates and date column is called date1
|
|
|
|
|
This gives the same result as mine above, but is far less readable and far less efficient.
Get friendly with the GROUP BY functionality of sql if you want to aggregate data.
|
|
|
|
|
Hi,
I wanna ask How can I verify that my TCP/IP connection to the server is working well???
My code is:
string sConnection = "Provider=SQLNCLI.1;Persist Security Info=False;User ID=sa;Initial Catalog=GMAO;Data Source=127.0.0.1,1433;Password=sa;";
string sSQL = "SELECT com FROM energie; ";
SqlConnection conn = new SqlConnection(sConnection);
SqlCommand comm = new SqlCommand(sSQL, conn);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sSQL,conn);
SqlDataReader dr = null;
try
{
comm.Connection.Open();
da.Fill(ds, "SQL Temp Table");
foreach (DataRow d in ds.Tables[0].Rows)
{
MessageBox.Show("xxxx");
comboBox1.Items.Add(d.ItemArray[0].ToString());
}
}
catch (SqlException ex)
{
MessageBox.Show("connexion impossible");
MessageBox.Show(ex.Message);
return;
}
dr.Close();
comm.Connection.Close();
the error that must appears when connection is failed doesn't existe when running,IS it an indice that my connection goes well??
When googling,I found that the job activity monitor in the sql server management indicates that.is that true??how can I use that in checking my connection result???
Thanks
|
|
|
|
|
well firstly 127.0.0.1 is a ping back address..
to programatically ping an address have a look at this example ping example
what is the error message that you are getting?
Marc Clifton wrote: That has nothing to do with VB. - Oh crap. I just defended VB!
|
|
|
|
|
Hi,
I wanna explain to u something:First,I work with the defualt instance of sql server 2005.So the server availabe is:Admin-PC\MSSQLSERVER that indicates a local IP@=127.0.0.1,1433.Is that true or I am wrong in my behavior?
Second,what u mean by ping back @??
Third,bebore attaching my database,the error"Specified sql server not found or access denied"annoys me.after the attachemment,no exception appears(in the catch block of my code)but still my combobox not filled by data from database.
Thanks a lot
|
|
|
|
|
127.0.0.1 is normally an address you use to test a machines network card.
if you run a command prompy and type ipconifg you will see your network address is different.
on your connection string i would change the ip address for the name of the machine and try that
Marc Clifton wrote: That has nothing to do with VB. - Oh crap. I just defended VB!
|
|
|
|
|
|
Hi,
I am successfully stored & retrieved image files of size less than 64 KB.But when I am storing a image file of size 3 MB, then there is no error,but it only stores partial data in database.
Please refer the code:
------------------------------------------------------------------
1. File CMyDb.hpp----->
class CMyDb : public CDatabase
{
public:
CMyDb();
virtual ~CMyDb();
virtual void BindParameters( HSTMT hstmt );
BYTE* m_pabImage; // address of the data of the blob
int m_nImageLen; // sizeof the data in the image, in bytes
CString m_sStmt; // looks like "UPDATE MyTable SET myFld=?
WHERE idxFld=123"
};
------------------------------------------------------------------
2. File CMyDb.cpp----->
CMyDb::CMyDb()
{
m_pabImage = NULL;
m_nImageLen = 0;
}
CMyDb::~CMyDb()
{
}
void CMyDb::BindParameters( HSTMT hstmt)
{
SQLINTEGER nLenOrInd= m_nImageLen;
SQLRETURN rc;
if ( m_sStmt.Find("?") == -1 )
{ // no binding needed
return;
}
rc= SQLBindParameter(
hstmt, (SQLSMALLINT)1, SQL_PARAM_INPUT, SQL_C_BINARY,
SQL_LONGVARCHAR,
m_nImageLen, 0, (void*)m_pabImage, m_nImageLen, &nLenOrInd);
}
------------------------------------------------------------------
3. File Main.cpp->
CFile file (sFileName, CFile::modeRead);//|CFile::typeBinary);
CFileStatus fileStatus;
file.GetStatus(fileStatus);
int nCntImgBytes= 3 * 1024 * 1024;//3MB buffer
BYTE* pabData = (BYTE*)calloc(nCntImgBytes,sizeof(BYTE));
DWORD lTemp = file.ReadHuge((void*)pabData,fileStatus.m_size);
pApp->pServerDatabase->m_pabImage = pabData;
pApp->pServerDatabase->m_nImageLen = fileStatus.m_size;
pApp->pServerDatabase->m_sStmt= "INSERT INTO TEST1 (\"NAME\" , \"myBlobfield\") VALUES ('2',?)";
pApp->pServerDatabase->ExecuteSQL( pApp->pServerDatabase->m_sStmt );
------------------------------------------------------------------
Please reply me as soon as possible.
Regards
Navneet
|
|
|
|
|
There could be a size limit of the BLOB data type in the database engine you use here. I do not think that all database engines throw an exception when the data is more than the specified field can store, it seems your database just trims it down.
I guess a better solution is to store the file somewhere on the file system, and to store the filename (including path) only in the database.
|
|
|
|
|
what database are you using?
Marc Clifton wrote: That has nothing to do with VB. - Oh crap. I just defended VB!
|
|
|
|
|
Hi,
I am using Interbase 6.0 database.
My database table structure is like:
Create table "TEST"
(
"NAME" VARCHAR(10),
"BLOB_DATA" BLOB
)
Interbase 6.0 database only supports BLOB for storing images.It don't support LONGBLOB & other datatypes.
|
|
|
|
|
The BLOB type in your database seems limited to 64KB. There may be a larger type though.
Example: MySQL has TINYBLOB, MEDIUMBLOB, BLOB, and LONGBLOB.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
i what to have an insert transact in ms access 2003
this insert statement should retrieve an ID from another table and then
insert informations
some thing like :
insert into myTable values(123,'123',123,123,
(select DISTINCT ID from ServiceGroupsInfo where NodeName='abc') )
but it does not work
what should i do?????
please help me!
|
|
|
|
|
reza assar wrote: but it does not work
what should i do?????
In the first instance I would suggest you read the forum guidlines, In the second I would define "Doesn't work".
|
|
|
|
|
Looks to me like you are missing the field list. Eg.
insert into myTable
(field1, field2, field3, field4, field5)
values(123,'123',123,123,(select DISTINCT ID from ServiceGroupsInfo
where NodeName='abc'))
though I would further modify it to:
insert into myTable
(field1, field2, field3, field4, field5)
Select Distinct
123,'123',123,123, ID
from ServiceGroupsInfo
where NodeName='abc';
I'm not convinced by the distinct either, as surely ServiceGroupsInfo is unique by NodeName , or it will give multiple results for ID anyway.
|
|
|
|
|
hi,
I have to search 90% characters in a string.
Suppose the string is "abcdef"
and it;s character length is 6
and it's 90 percent character length will be 5
Now i have to search it's any 5 character in the following string
string1
stringabcdef
astrbincgdef
Please suggest something ...
Is there any way to do so with loop
Thanks
|
|
|
|
|
For that you need to write either Stored Procedure or Function.
Just calculate length of the search string,
and also need to calculate how many characters for 90% it.
Then you need to search character by character..
Sounds Non-trivial.
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
How about the following...
-- return 90% of a string
declare @s varchar(6)
set @s = '123456'
select substring(@s, 1, cast(floor(0.9 * len(@s)) as int))
-- usage
select *
from [table]
where charindex(substring(@s, 1, cast(floor(0.9 * len(@s)) as int)), [field]) > 0
Ryan
|
|
|
|
|
hi,
RyanEK wrote: -- return 90% of a string declare @s varchar(6)
set @s = '123456' select substring(@s, 1, cast(floor(0.9 * len(@s)) as int))
-- usage
select *
from [table]
where charindex(substring(@s, 1, cast(floor(0.9 * len(@s)) as int)), [field]) > 0
Thanks for the kind attention. It will work fine if I have to start from position 1 only.
But the string to search that I mentioned in the post. was abcdef
and it's 90% can be abcde or bcdef
similarly i can have larger strings as well and it's propability will be have more string to search.
Is it possible to resolve it without any iteration ?
Thanks
|
|
|
|
|
Ahh I see, you want to match a percentage of a string regardless of its position. I suggest you create a temp table holding all possible values and join to that.
eg. 25% of 'ABCDEFGHIJ' would yield a table with the rows:
'AB'
'BC'
'CD'
etc...
Ryan
|
|
|
|
|
hi Ryan,
Thanks for the reply.
Actually i wanted to search 90% in a non consecutive way.
Example
the string to search is abcdef
it's original length is 6
it's 90% length is 5.
and i want to search any five characters from this 90% in a non consecutive way
from the following records.
"Search Matched" - Non matched because only 4 characters matched
"Sabaschede" - matched and found five characters in it.
can i do it without using any loop ? And I have millions of records, also have to consider it's performance
|
|
|
|
|
Interesting problem. This may be a solution? Say you have a string "abcdef".
<br />
-- place each character in a temp table<br />
declare @temp table (ch char)<br />
insert into @temp values ('a')<br />
insert into @temp values ('b')<br />
insert into @temp values ('c')<br />
insert into @temp values ('d')<br />
insert into @temp values ('e')<br />
insert into @temp values ('f')<br />
<br />
-- some test data<br />
declare @temp2 table (string varchar(10))<br />
insert into @temp2 values ('Sabaschede')<br />
insert into @temp2 values ('aaaaaaaaaa')<br />
insert into @temp2 values ('a1b2c3d4e5')<br />
<br />
-- use a cross join to determine how many times each character appears in the string field<br />
-- you just need to determine that 90% of 'abcdef' is 5 characters<br />
select string<br />
from (<br />
select ch, string, case when charindex(ch,string) > 0 then 1 else 0 end chrcount<br />
from @temp<br />
cross join @temp2<br />
) as t<br />
group by string<br />
having sum(chrcount) >= 5<br />
Ryan
|
|
|
|
|
Hay everyone,
I am using CDOSYS to send emails from my sql server 2000. Now the problem is that when i am sending normal emails it's working fine but when i am sending emails that are larger than 8k it timeouts. By the way the email content is also html.
anyone has any ideas or has delt with this problem before?
Regards,
Christian Pace
|
|
|
|
|
Since CDOSYS is a builtin tool in ASP.NET, you may be more likely to get an answer in the ASP.NET forum instead of the SQL Forum.
|
|
|
|
|
I'm attempting to build a Version calculator that will increment based on a depth field. I need this to execute inside a Stored Proc. My depth is 5.
For example, I have 1.1 so the next time I call the Stored Proc it will be 1.2, 1.3, 1.4, 1.5. After it fills up based on that depth I want it to go down to the next level so the next one would be 1.1.1. The next would be 1.1.2, 1.1.3, etc... Once that bottom version fills out it will only go up one level. ie: 1.2.1, 1.2.2, 1.2.3, ...
|
|
|
|