Showing posts with label everybody. Show all posts
Showing posts with label everybody. Show all posts

Sunday, March 11, 2012

Multiple Records Subquery..

Hi everybody,

I like to display the records for AccountNo = 221 from table records shown below, how would I do this? I am display this results in a crystal report. What is sql statement to do this? Thanks.

Sql Statement: (this statement is not allowed)
Select AccountNo, RecordID, (Select Description From Table1 Where RecordID In (Select RecordID From Table2 Where Date < '04/05/2006')) As Description, Amount From Table2 Where Date < '04/05/2006'


Desired Result:

AccountNo RecordID Description Amount
221 20 Whew 290.00
221 21 Hi There Good Morning 728.00

Table 1

RecordID Description
20 Whew
21 Hi
21 There
21 Good Morning

Table 2
Date AccountNo RecordID Amount
04/02/2006 220 19 80.0
04/03/2006 221 20 290.0
04/04/2006 221 21 728.0
04/06/2006 223 23 200.3
04/07/2006 225 25 2893.20

den2005

select t2.AccountNo, t1.RecordId, t2.Description, t1.Amount

from Table1 t1 inner join Table2 t2 on t1.RecordId = t2.RecordId

where t2.AccountNo = 221 and t2.Date < '4/5/2006'

|||

Hi,

Thanks for replying, I f I do that teh results would be,

AccountNo RecordID Description Amount
221 20 Whew 290.00
221 21 Hi 728.00

221 21 There 728.00

221 21 Good Morning 728.00

But I want to display shown below,

AccountNo RecordID Description Amount
221 20 Whew 290.00
221 21 Hi There Good Morning 728.00

Besides that is my first statement using inner join...

den2005

|||How do you determine that it is "Hi There Good Morning" and not "Good Morning Hi There" and not "There Hi Good Morning" etc.

Is there another column that will determine the required order ?

Do take not that, records are stored in database in no particular order. When returning the records, you have to determine the sequence by using ORDER BY.

How to insert a byte() to a blob column?

Hi everybody,

I don't where to asked this question in this forum. How do you insert to a column of a table with a blob or binary datatype if there is one, from a byte() datatype? What is wrong? How can I fixed this? I need help. Thanks.

Code:
string sqlText = "Insert table1(id, dataByte) values('" + id + "'," + byteData + ")";

OdbcCommand cmd = new OdbcCommand(sqlText, odConn);

//opening connection here

int iRes = cmd.ExecuteNonQuery();

Result:
iRes = -1
den2005parameterize, parameterize, parameterize
read up on parameters

on a side note - never build sql!
on another side note. . . don't use odbc (there are bugs in the MDAC sql odbc driver)
use oledb. . .
better yet - use the sqlclient library

untested code (might have missed a particular point but this is the gist):



SqlDbCommand cmd = new SqlDbCommand("Insert table1(id, dataByte) values(@.id , @.data)", sqlConn);
cmd.Parameters["@.id"].ParameterValue = id;
cmd.Parameters["@.data"].ParameterValue = byteData;
int iRes = cmd.ExecuteNonQuery()

Research "how to store an image in a database" - its the same concept.
Again. . . parameterize your queries.
Insist that your peers do the same.

Security - Performance - Maintainence

and this question belongs in .Net Data Access Forum|||Thanks for reply, Blair Allen. I solved this my problem now is retrieving this BLOB from database and converting it to byte() and loading it to a Micorosft.Ink object using Ink.Load() method. The error occurs at Ink.Load() statement. Can anyone help? Thanks for advise. I'll post this problem at .Net Data Access Forum.

den2005|||I think this is it:
just hacked, not checked


byte[] bytes = null;
/* first get the size. . . */
int num = MySqlDataReader.GetBytes("myBlobField", 0, null, 0, int.MaxValue);
if (num != 0)
{
/* allocate the bytes */
bytes = new byte[num];
/* load the bytes */
MySqlDataReader.GetBytes("myBlobField", 0, bytes, 0,num)
}

cheers|||Thanks Blair Allen for reply I used a different approach. I converted the byte() to a base64 string format and then store it as a Text data in database and retrieving it as string and used Convert.FromBase64String() method to convert it back to byte() and load it to Ink.Load() and it works.

den2005

Thursday, March 8, 2012

[NEWBIE] Replication with MSDE 2000

Hi everybody,
can someone help me about replication ?
I want to install msde2000 on two machines (identical) and keep database
updated like mirroring, so my users can connect to mirrored data if primary
server crashed down.
The two machines are in my LAN with their own IP number
Is it Possible ?
Thanks in advance and sorry of my poor knowledge of MSDE features
Merlinweb
Hi Merlinweb,
Merge replication goes close to doing what you want if you keep it
synchronizing constantly. There is some latency with the updates but that's
ok in many scenarios. It works very well when the servers are on the same
LAN. You will need to consider though, how to make schema changes, etc. as
that introduces quite a few issues.
HTH,
Greg Low [MVP]
MSDE Manager SQL Tools
www.whitebearconsulting.com
"il_Leva" <il_levaMACIAO@.hotmail.com> wrote in message
news:41c97bf0$1@.x-privat.org...
> Hi everybody,
> can someone help me about replication ?
> I want to install msde2000 on two machines (identical) and keep database
> updated like mirroring, so my users can connect to mirrored data if
> primary
> server crashed down.
> The two machines are in my LAN with their own IP number
> Is it Possible ?
> Thanks in advance and sorry of my poor knowledge of MSDE features
> Merlinweb
>
|||"Greg Low [MVP]" <greglow@.lowell.com.au> ha scritto nel messaggio
news:uDw9mGI6EHA.2584@.TK2MSFTNGP10.phx.gbl...
> Hi Merlinweb,
> Merge replication goes close to doing what you want if you keep it
> synchronizing constantly. There is some latency with the updates but
that's
> ok in many scenarios. It works very well when the servers are on the same
> LAN. You will need to consider though, how to make schema changes, etc. as
> that introduces quite a few issues.
Thank you very much !
Now I go and search something useful on the net about merge replication.
Cheers
Merlinweb

Tuesday, March 6, 2012

[MS Sql] Data type nvarchar

Hi everybody,

I'm using SQL Server Management Studio Express.
I'm trying to create a field which contains a text entered by the user. So, it should be able to contain at least 500 characters.

I used the type "nvarchar(MAX)". The problem is that the type contains about 50 characters max!!
I couldn't find out where and how to fix that.
If you have any idea :)

Thanks a lotType over the the MAX with the desired length of 500.|||Hi tmorton
Of course I tried nvarchar(500) (forgot to tell that). But it's not working either.
It sounds like nvarchar(MAX) is the max length type, and limited to about 50...
Thanks for your reply. And if someone has any idea :)|||That's all it takes from the SQL Server end. If you are only managing to store 50 characters in that column, then I would venture a guess that your data is being truncated before it hits the database. What does your code look like that is adding the data to your table?|||I believe that SQL Management Studio truncates text that it displays. Use something else to view/edit the column.|||Hi
It's weird, it's working now. And yet I didn't change anything particular. Maybe a "bug" on SQL Server... weird though. Thanks a lot to you guys :)

Friday, February 24, 2012

[help] installation problems with sql server express 2005

hello everybody
I've downloaded a free version of ms sql server express 2005
and while I lauch the install file, I Have a bug :
Something like :
"you don't have write and read permission" - conctact administator
but i'm logged on a administator session

if anyone can help me ..
thnx in advance ..
hzben

Hi,

Ensure you have Read & Write permission on the folder/drive you are trying to install SQL Server , i.e. Program Files folder!!! www.windowsecurity.com/articles/Understanding-Windows-NTFS-Permissions.html FYI.

Hemantgiri S. Goswami

|||thank you for this reply
Do i can export a sql 2000 database to sql 2005 express only with a .sql file or do i need the .mdf and .ldf files of my old database ?
I need to export only the structure (tables ,columns and triggers) of my database to sql express 2005 .
have a nice day !!
hzben|||

Hi hzben,

you can export the structure of your database with your .sql file (Script of Database Objects) and for that you don't need .mdf/.ldf files. But in case you wants to attach your database to sql server you require .mdf and .ldf.

HTH

Hemantgiri S. Goswami

Thursday, February 16, 2012

[ask] how to invoke sqldatasource command in method?

hello everybody, i have a question to ask,

suppose i have a sqldatasource, can i use it in a method??

this is my case, i need to make a new method to count the rows in a datagrid, so i will have to read the sqldatasource. the problem is, how to retrieve it?? usually i use the built in sqldatasource_selected to count the rows...

is there any other way??

Lets have a binddata method

privatevoid BindData()

{

SqlDataSource1.SelectCommand =

"Select * from clients";

}

Call the above method in PageLoad or any other desired Event

In theSqlDataSource1_Selected

retrive the total rows

protectedvoid SqlDataSource1_Selected(object sender,SqlDataSourceStatusEventArgs e)

{

Label1.Text = e.AffectedRows.ToString();

}

Hope this will help you.

let me know if need further clarifications

|||

yupz i know that, but that doesn't solve my problem

if i save the total row to a variable, let's say countRow = e.AffectedRows, how can i pass this value to another method??

(i need this value to be added by 1 so i can use it for the next primary key)

|||

Store it in a Viewstate or Session Variable

Set Value

Session[

"RowCount"] = e.AffectedRows;

ViewState[

"RowCount"] = e.AffectedRows;

Getvalue

int rowCount1 =int.Parse(Session["RowCount"].ToString());

int rowCount2 =int.Parse(ViewState["RowCount"].ToString());

If you need to access the value even in otherpage use Session or Viewstate itself ok

|||

oww yes, session variable...i completely forget it :)

thx so much bro...

but that viewstate variable...what is the difference??

btw thx so much bro

|||

The values stored in session will be available through out the Session of a particular user irrespective of the page he/she is navigating.

Value stored in viewstate will be available only in the page in which it have been set.

More over in Viewstate you can place only string ,in Session variable you can place any object

Have a look into these links

http://hiltong.blogspot.com/2004/11/viewstate-vs-session-state-vs.html

http://aspalliance.com/articleViewer.aspx?aId=135&pId=

Hope this will help you

|||well...thank you very much bro