Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Sunday, March 25, 2012

Asp to asp.net convertor

I would like to know about the website who had convert the code asp to asp.net

please help me

Ashwani Kumar

I'd be surprised if this could be done.

It's not a case of changing syntax or replacing all "A"s with "B"s. You're replacing all your Response.Write or HTML strings with controls and I can't see how aany converter could tell that your HTML block needs to be replaced with a gridview, formview or repeater.

I'm willing to be proved wrong though!

|||

Thanks

|||

For migrating sites from ASP to ASP.Net my suggestion is to follow this migration guide.

http://www.asp.net/downloads/archived/migration-assistants/asp-to-aspnet/

|||

Yes. This can be donw. The ASP to ASP.NET Migration Assistant is designed to help you convert ASP pages and applications to ASP.NET. It does not make the conversion process completely automatic, but it will speed up your project by automating some of the steps required for migration.

You can download at:http://msdn2.microsoft.com/en-us/asp.net/aa336624.aspx

Also see how to use this assistance tool : http://www.asp101.com/articles/john/asptoaspnet/default.asp

Hope my suggestion helps

This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

Thursday, March 22, 2012

ASP Code to Monitor Scheduled SQL Jobs via the web

Hi Guys,

I'm Hoping some one could help me out, I'm in need of creating a web interface to monitor scheduled SQL Jobs, both on sql 2000 & 2005.

I'm new to asp, Can anyone point me in the right direction.Really appreciate it.

Regards

This should get you started for SQL2005.

<%@. Page Language="VB" EnableTheming="False" %><%@. ImportNamespace="System.Data" %><%@. ImportNamespace="System.Data.SqlClient" %><!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)If Not Page.IsPostBackThen JobHistory_GridView.DataSource = FJobHistory_GridView() JobHistory_GridView.DataBind()End If End Sub Function FJobHistory_GridView()As System.Data.IDataReaderDim SelectConnAs New SqlConnection("SQL_Server_ConnectionString_With_User_That_Can_Access_MSDB_Database")Dim SelectCmdAs New SqlCommand() SelectCmd.CommandText ="msdb.dbo.sp_help_jobactivity" SelectCmd.CommandType = CommandType.StoredProcedure SelectCmd.Connection = SelectConn SelectConn.Open()Dim dataReaderAs IDataReader = SelectCmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)Return dataReaderEnd Function </script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>SQL Job History</title></head><body> <form id="form1" runat="server"> <div> <asp:GridView ID="JobHistory_GridView" runat="server" AutoGenerateColumns="True"> </asp:GridView> </div> </form></body></html>
|||

Thanks a mil Brad,

This will def come in handy, I'm new at this company, i've noticed that they already have a web interface set up to monitor sql jobs, at present it is setup to monitor jobs on sql 2000, I need to now get this working with sql2005, I've configured everything neccessary on the config & aspx pages. I get a connection to sql 2005, I know this because as part of the monitoring tool you are able to view proccesser info as well, I can view this information of the the sql 2005 server however it does not display the jobs. (Just Blank)

Any idea why this might be? I could post the code if that would help.

Thanks again for your assistance.

BR

|||

Try this for the gridview instead

 <asp:GridView ID="JobHistory_GridView" runat="server" AutoGenerateColumns="False" DataKeyNames="session_id,job_id"> <Columns> <asp:BoundField DataField="session_id" HeaderText="session_id"ReadOnly="True" /> <asp:BoundField DataField="job_id" HeaderText="job_id"ReadOnly="True" /> <asp:BoundField DataField="job_name" HeaderText="job_name" /> <asp:BoundField DataField="run_requested_date" HeaderText="run_requested_date" /> <asp:BoundField DataField="run_requested_source" HeaderText="run_requested_source" /> <asp:BoundField DataField="queued_date" HeaderText="queued_date" /> <asp:BoundField DataField="start_execution_date" HeaderText="start_execution_date" /> <asp:BoundField DataField="last_executed_step_id" HeaderText="last_executed_step_id" /> <asp:BoundField DataField="last_executed_step_date" HeaderText="last_executed_step_date" /> <asp:BoundField DataField="stop_execution_date" HeaderText="stop_execution_date" /> <asp:BoundField DataField="next_scheduled_run_date" HeaderText="next_scheduled_run_date" /> <asp:BoundField DataField="job_history_id" HeaderText="job_history_id" /> <asp:BoundField DataField="message" HeaderText="message" /> <asp:BoundField DataField="run_status" HeaderText="run_status" /> <asp:BoundField DataField="operator_id_emailed" HeaderText="operator_id_emailed" /> <asp:BoundField DataField="operator_id_netsent" HeaderText="operator_id_netsent" /> <asp:BoundField DataField="operator_id_paged" HeaderText="operator_id_paged" /> </Columns> </asp:GridView>
If that doesnt work, post your code.

ASP AND SQL SERVER 2005

i cannot connect to my local server.my code is

<%
ad=request.form("ad")
soyad=request.form("soyad")
email=request.form("email")
dim conn
set conn=CreateObject("ADODB.Connection")
conn.open "Server=./SQLEXPRESS;Database=NEWSWORLD;Trusted_Connection=True;"
sqlifadesi="insert into user_info(ad,soyad,email) values('"&ad&"','"&soyad&"','"&email&"')"
conn.execute(sqlifadesi)
conn.close
set conn=nothing
response.write "bilgileriniz kayit edildi,Ilginiz i?in tesekkür ederiz"
%>

it shows error page in

conn.open "Server=./SQLEXPRESS;Database=NEWSWORLD;Trusted_Connection=True;"

i dont use native client because i dont use .net i want to make a connection to sql server 2005 with classic ASP.

Thanks for replies

Hi Ibrahim,

which error are you getting ?

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de|||

thnx for reply Jens Suessmeyer

when i use this code i get this error .... Microsoft OLE DB Service Components (0x80040E21) Work isnt done

<%

ad=request.form("ad")

soyad=request.form("soyad")

email=request.form("email")

dim conn

set conn=CreateObject("ADODB.Connection")

conn.open "data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|NEWSWORLD.mdf;User Instance=true"

sqlifadesi="insert into user_info(ad,soyad,email) values('"&ad&"','"&soyad&"','"&email&"')"

conn.execute(sqlifadesi)

conn.close

set conn=nothing

response.write "bilgileriniz kayit edildi,Ilginiz i?in tesekkür ederiz"

%>

when i use this code i get this error...Microsoft OLE DB Provider for ODBC Drivers (0x80004005)

<%

ad=request.form("ad")

soyad=request.form("soyad")

email=request.form("email")

dim conn

set conn=CreateObject("ADODB.Connection")

conn.open "Server=.\SQLEXPRESS;Database=NEWSWORLD;Trusted_Connection=True;"

sqlifadesi="insert into user_info(ad,soyad,email) values('"&ad&"','"&soyad&"','"&email&"')"

conn.execute(sqlifadesi)

conn.close

set conn=nothing

response.write "bilgileriniz kayit edildi,Ilginiz i?in tesekkür ederiz"

%>

i have been working on it cant find a solution.when i use vb.net i can connect to sql server 2005 by using this "Server=.\SQLEXPRESS;Database=NEWSWORLD;Trusted_Connection=True;" but in classic asp i cant connect

Thank u

|||

i have solved my problem thank u i have done like this

<%
ad=request.form("ad")
soyad=request.form("soyad")
email=request.form("email")
dim conn
set conn=CreateObject("ADODB.Connection")
conn.open "Provider=SQLNCLI;Server=.\SQLEXPRESS;Database=NEWSWORLD;Tru sted_Connection=yes;"
sqlifadesi="insert into user_info(ad,soyad,email) values('"&ad&"','"&soyad&"','"&email& ; ;"')"
conn.execute(sqlifadesi)
conn.close
set conn=nothing
response.write "bilgileriniz kayit edildi,Ilginiz i?in tesekkür ederiz"
%>

i have done it with SQL Native Client with no username and password.

Thanks for replies

sql

Tuesday, March 20, 2012

Asking for Column data type

This is an easy one , I need to know the way to check programatically for an SQL server 2000 column data type , if the result is a code , which codes are for the diferent datatypes ( varchar , text , smallint , etc ) , if you send me an url is ok.
thank youselect DATA_TYPE
from Information_Schema.Columns
where table_name = 'table_name'|||Thanks

Monday, March 19, 2012

Ascii Code search

Hi;
I'm tring to create a sql query in 6.5 that will find any unprintable
characters in a text field. I'm trying to use a where clause that looks
for specific ASCII codes but cant seem to get it work. Does anyone have
any ideas how to do this.
Thanks
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!
David,
You can use below technique. In my example, I used CHAR(99) which is the letter 'c'. Replace this with the
ASCII code for the unprintable character you want to find.
SELECT *
FROM
(
SELECT 'abcdef' AS colname
UNION
SELECT 'abdef' AS colname
) AS d
WHERE CHARINDEX(CHAR(99), colname) > 0
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"David Cervelli" <cervelli@.adelphia.net> wrote in message news:OkpMIugiEHA.1348@.tk2msftngp13.phx.gbl...
> Hi;
> I'm tring to create a sql query in 6.5 that will find any unprintable
> characters in a text field. I'm trying to use a where clause that looks
> for specific ASCII codes but cant seem to get it work. Does anyone have
> any ideas how to do this.
> Thanks
>
>
> *** Sent via Developersdex http://www.codecomments.com ***
> Don't just participate in USENET...get rewarded for it!
|||Tibor
I finally tried this and it works great but I have a few issues that I
hope you might be able to help.
I'm using version 6.5 so a varchar is only 255 characters.
I'm trying to search a text field that is much larger then 255.
Your soltuion does a good job at searching a text field but not a text
field.
If I convert the text to varchar it only looks at the first 255
characters.
Do you have any suggestions?
Thanks in advance.
David
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!
|||If the function doesn't support the "text" datatype, then you probably have to use functions such as
TEXTPTR, READTEXT etc to loop through your data and use the function on chunks of data. Not very
fun...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"David Cervelli" <dcervelli@.ssgnet.com> wrote in message
news:uRwc0zXkEHA.3632@.TK2MSFTNGP09.phx.gbl...
>
> Tibor
> I finally tried this and it works great but I have a few issues that I
> hope you might be able to help.
> I'm using version 6.5 so a varchar is only 255 characters.
> I'm trying to search a text field that is much larger then 255.
> Your soltuion does a good job at searching a text field but not a text
> field.
> If I convert the text to varchar it only looks at the first 255
> characters.
> Do you have any suggestions?
> Thanks in advance.
> David
>
> *** Sent via Developersdex http://www.codecomments.com ***
> Don't just participate in USENET...get rewarded for it!

Ascii Code search

Hi;
I'm tring to create a sql query in 6.5 that will find any unprintable
characters in a text field. I'm trying to use a where clause that looks
for specific ASCII codes but cant seem to get it work. Does anyone have
any ideas how to do this.
Thanks
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!David,
You can use below technique. In my example, I used CHAR(99) which is the let
ter 'c'. Replace this with the
ASCII code for the unprintable character you want to find.
SELECT *
FROM
(
SELECT 'abcdef' AS colname
UNION
SELECT 'abdef' AS colname
) AS d
WHERE CHARINDEX(CHAR(99), colname) > 0
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"David Cervelli" <cervelli@.adelphia.net> wrote in message news:OkpMIugiEHA.1348@.tk2msftngp13
.phx.gbl...
> Hi;
> I'm tring to create a sql query in 6.5 that will find any unprintable
> characters in a text field. I'm trying to use a where clause that looks
> for specific ASCII codes but cant seem to get it work. Does anyone have
> any ideas how to do this.
> Thanks
>
>
> *** Sent via Developersdex http://www.codecomments.com ***
> Don't just participate in USENET...get rewarded for it!|||Tibor
I finally tried this and it works great but I have a few issues that I
hope you might be able to help.
I'm using version 6.5 so a varchar is only 255 characters.
I'm trying to search a text field that is much larger then 255.
Your soltuion does a good job at searching a text field but not a text
field.
If I convert the text to varchar it only looks at the first 255
characters.
Do you have any suggestions?
Thanks in advance.
David
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!|||If the function doesn't support the "text" datatype, then you probably have
to use functions such as
TEXTPTR, READTEXT etc to loop through your data and use the function on chun
ks of data. Not very
fun...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"David Cervelli" <dcervelli@.ssgnet.com> wrote in message
news:uRwc0zXkEHA.3632@.TK2MSFTNGP09.phx.gbl...
>
> Tibor
> I finally tried this and it works great but I have a few issues that I
> hope you might be able to help.
> I'm using version 6.5 so a varchar is only 255 characters.
> I'm trying to search a text field that is much larger then 255.
> Your soltuion does a good job at searching a text field but not a text
> field.
> If I convert the text to varchar it only looks at the first 255
> characters.
> Do you have any suggestions?
> Thanks in advance.
> David
>
> *** Sent via Developersdex http://www.codecomments.com ***
> Don't just participate in USENET...get rewarded for it!

Ascii Code search

Hi;
I'm tring to create a sql query in 6.5 that will find any unprintable
characters in a text field. I'm trying to use a where clause that looks
for specific ASCII codes but cant seem to get it work. Does anyone have
any ideas how to do this.
Thanks
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!David,
You can use below technique. In my example, I used CHAR(99) which is the letter 'c'. Replace this with the
ASCII code for the unprintable character you want to find.
SELECT *
FROM
(
SELECT 'abcdef' AS colname
UNION
SELECT 'abdef' AS colname
) AS d
WHERE CHARINDEX(CHAR(99), colname) > 0
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"David Cervelli" <cervelli@.adelphia.net> wrote in message news:OkpMIugiEHA.1348@.tk2msftngp13.phx.gbl...
> Hi;
> I'm tring to create a sql query in 6.5 that will find any unprintable
> characters in a text field. I'm trying to use a where clause that looks
> for specific ASCII codes but cant seem to get it work. Does anyone have
> any ideas how to do this.
> Thanks
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

Thursday, March 8, 2012

AS2005 Retreiving Data Problem

Hi All,

I'm having problem retreiving data from a AS2005.

I'm using a named instance, called Desktop126\SQL05

This code is being used:

using adomdnet = Microsoft.AnalysisServices.AdomdClient;

...

System.Text.StringBuilder result = new System.Text.StringBuilder();

using (adomdnet.AdomdConnection conn = new AdomdConnection("Data Source=Desktop126\\SQL05;Catalog=BuypassDW;Integrated Security=SSPI; ConnectTo=default")){

conn.Open();

//Create a command, using this connection

adomdnet.AdomdCommand cmd = conn.CreateCommand();

cmd.CommandText = @."

SELECT

{[Transactions Types].[ID].[All].Children} ON columns,

{[Merchants].[l Merchant Id].&[236553]} ON ROWS

FROM [Buypass DW1] WHERE( [Time].[Year].[2005])";

//Execute the query, returning a cellset

adomdnet.CellSet cs = cmd.ExecuteCellSet(); -- Fails with error:

// Either the user, DomainName\UserName, does not have access to the BuypassDW database, or the database does not exist.

conn.Close();

result.Append("\t");

adomdnet.TupleCollection tuplesOnColumns = cs.Axes[0].Set.Tuples;

foreach (adomdnet.Tuple column in tuplesOnColumns)

{

result.Append(column.Members[0].Caption + "\t");

}

result.AppendLine();

//Output the row captions from the second axis and cell data

//Note that this procedure assumes a two-dimensional cellset

adomdnet.TupleCollection tuplesOnRows = cs.Axes[1].Set.Tuples;

for (int row = 0; row < tuplesOnRows.Count; row++)

{

result.Append(tuplesOnRows[row].Members[0].Caption + "\t");

for (int col = 0; col < tuplesOnColumns.Count; col++)

{

result.Append(cs.Cells[col, row].FormattedValue + "\t");

}

result.AppendLine();

}

conn.Close();

} // using connection

}

Any idea why this is failing, the user has permissionto to access the source database,

in AS the datasource has the follwoing value for impersonation info ( AS2005-->dataource-->property)

ImpersonateCurrentUser.

Also in the AS2005 service the DomainName\UserName is being added .

Any hlep will be appreciated.

Thanks.

Abdu

Looks like you havent granted your users access to Analysis Services database.

Create a new role in BypassDW database, add your domain\user to the new role and grant the role DB admin rights. See if user can issue a query.

If everything works, change your role permissions to allow new role read only access to the cubes in the database.

Edward Melomed.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

AS/400 with Arabic Code Page (420)

Hi yeah.

I am doing a project which retrieves data from a AS/400 machine.
The code page of the machine is 420.
I used "OLE DB\IBM DB2 UDB for iSeries IBMDASQL OLE DB Provider" to connect from SQL Server.
The problem is, all the arabic characters coming from this machine becomes unreadable, becoming some machine code text.
What could be the problem and how can I solve this?

Thank you.

Did you try setting the code page value explictly in your ole db source connection?

Thanks

|||

Yes, I'd try to set to 420 in my OLE DB connection, but it still does not work.

I had tried putting nvarchar, add the data conversion in between, using various drivers, ODBC, OLE DB, DB2, iSeries driver, forcing CCSID in AS/400 machine and still unable to extract the data properly.

Would it be the AS/400 problem or my SSIS setting problem?

Friday, February 24, 2012

Arrays in a Stored Procedure

Can any one help me with a sample code, which can take an array of

elements as one of it's parameters and get the value inserted into a table in a

stored procedure.

Thanks in advance

vnswathi.

SQL dosen't support array, so how do you want to passing an 'array' of elements as parameters to a stored procedure? Maybe you can use a string that delimits the elements of an array by some character(s) and then split the string into a set of values that can be inserted into a table. If so, the key point is how to split the string with specific delimitor, and you can take a look at this post:

http://forums.asp.net/thread/1300724.aspx

Array Problem

Hi All,

I have this code below:
Dim a As Integer = 0
While a <= myArray.Length()
Conn.Open()
Dim UpdateCmd As New SqlClient.SqlCommand("Update email_addr SET category = 'Deleted' where HP = @.hp", Conn)
UpdateCmd.Parameters.Add("@.hp", SqlDbType.VarChar, 50).Value = myArray(a)
UpdateCmd.ExecuteNonQuery()
a = a + 1
Conn.Close()
End While

BUt, When I run it, I receive error "Prepared statement '(@.hp varchar(50))Update email_addr SET category = 'Deleted' wher' expects parameter @.hp, which was not supplied. "

DOes anyone have the solution?

Thanks...

You are performing update in a LOOP ?

why not this :

update email_addr

set category = 'Deleted'

where HP in ('1', '2', '3', '4') -- array value here

Array in TSQL?

Hello,
I have some code that adds a new user. The new user has a checkboxlist of
items which they can be associated with. I would like to send this list of
items to TSQL along with the new user information. I would guess to combine
the selected items like so: "6,4,8,19,2".
Kind of do the following:
INSERT into tblUser (fields) VALUES (data)
Declare @.userID as integer
SET @.UserID = @.@.IDENTITY
for each item in @.Selected
INSERT into tblSelections (field) VALUE (item, @.UserID)
I know above isn't exactly possible, but can something similiar be done? I
dont want to have to run a proc for each item from my asp.net pages...
Thanks,
David Lozzi
Web Applications Developer
dlozzi@.(remove-this)delphi-ts.comIt would definetely be easiest to call a proc each time. Othewise you
could pass in the comma seperated string into the proc, and then do a
while loop with that string.
While CharIndex(",",@.Selected) != 0
Begin
-- Get Value before first comma code
-- Insert value code
-- Delete first value and comma code
End|||David Lozzi (DavidLozzi@.nospam.nospam) writes:
> I have some code that adds a new user. The new user has a checkboxlist
> of items which they can be associated with. I would like to send this
> list of items to TSQL along with the new user information. I would guess
> to combine the selected items like so: "6,4,8,19,2". >
> Kind of do the following:
> INSERT into tblUser (fields) VALUES (data)
> Declare @.userID as integer
> SET @.UserID = @.@.IDENTITY
> for each item in @.Selected
> INSERT into tblSelections (field) VALUE (item, @.UserID)
> I know above isn't exactly possible, but can something similiar be done? I
> dont want to have to run a proc for each item from my asp.net pages...
See http://www.sommarskog.se/arrays-in-sql.html#iterative for some
solutions.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||You have missed the foundations of RDBMS and really need to get a book
or a class before you try to code anything.
You want to violate First Normal Form (1NF). All data values are
scalar; there are no arrays. Each of those attribures would be a
separate column.
Rows are not records; fields are not columns; tables are not files.
We do not put silly redundant prefixes like "tbl-" on table names.
Look up ISO-11179.
I hope you know that IDENTITY cannot be a relational key by definition.
But you are using a bad thing in the wrong way. It mimics a
sequential file record number counter without your intervention when
you declare it as part of the DDL.
Do you know about check digits, a Regular Expression or some other rule
to validate your user id?
SQL is a set-oriented language, so you can insert a query result into a
base table or updatable VIEW. You are writing SQL like it was a 3GL.
You need a lot more help thanyou can get in a Newsgroup.|||I believe SQL Server 2005 supports arrays. I'm just getting into it, though.
HTH,
Kevin Spencer
Microsoft MVP
.Net Developer
A watched clock never boils.
"--CELKO--" <jcelko212@.earthlink.net> wrote in message
news:1130887553.702237.72860@.g49g2000cwa.googlegroups.com...
> You have missed the foundations of RDBMS and really need to get a book
> or a class before you try to code anything.
> You want to violate First Normal Form (1NF). All data values are
> scalar; there are no arrays. Each of those attribures would be a
> separate column.
> Rows are not records; fields are not columns; tables are not files.
> We do not put silly redundant prefixes like "tbl-" on table names.
> Look up ISO-11179.
> I hope you know that IDENTITY cannot be a relational key by definition.
> But you are using a bad thing in the wrong way. It mimics a
> sequential file record number counter without your intervention when
> you declare it as part of the DDL.
> Do you know about check digits, a Regular Expression or some other rule
> to validate your user id?
> SQL is a set-oriented language, so you can insert a query result into a
> base table or updatable VIEW. You are writing SQL like it was a 3GL.
>
> You need a lot more help thanyou can get in a Newsgroup.
>|||trival, wrtite a user function that converts a comma seperated list into a
table (the sql equiv of an array)
create function dbo.parseList (@.s varchar(2000))
returns @.values table (value varchar(2000))
as begin
declare @.v varchar(2000) ,@.i int
set @.i = patIndex('%,%',@.s)
while @.i > 0 begin
insert @.values values (substring(@.s,1,@.i-1))
set @.s = substring(@.s,@.i+1,len(@.s) - @.i)
set @.i = patIndex('%,%',@.s)
end
insert @.values values (@.s)
return
end
then call like:
INSERT into tblUser (fields) VALUES (data)
SET @.UserID = scope_identity()
INSERT tblSelections (field,userid)
select value, @.UserID
from dbo.parseList(@.selected)
-- bruce (sqlwork.com)
"David Lozzi" <DavidLozzi@.nospam.nospam> wrote in message
news:e03WQ9y3FHA.3600@.TK2MSFTNGP12.phx.gbl...
> Hello,
> I have some code that adds a new user. The new user has a checkboxlist of
> items which they can be associated with. I would like to send this list of
> items to TSQL along with the new user information. I would guess to
> combine the selected items like so: "6,4,8,19,2".
> Kind of do the following:
> INSERT into tblUser (fields) VALUES (data)
> Declare @.userID as integer
> SET @.UserID = @.@.IDENTITY
> for each item in @.Selected
> INSERT into tblSelections (field) VALUE (item, @.UserID)
> I know above isn't exactly possible, but can something similiar be done? I
> dont want to have to run a proc for each item from my asp.net pages...
> Thanks,
> --
> David Lozzi
> Web Applications Developer
> dlozzi@.(remove-this)delphi-ts.com
>
>|||Thanks for your help.
:-|
David Lozzi
Web Applications Developer
dlozzi@.(remove-this)delphi-ts.com
"--CELKO--" <jcelko212@.earthlink.net> wrote in message
news:1130887553.702237.72860@.g49g2000cwa.googlegroups.com...
> You have missed the foundations of RDBMS and really need to get a book
> or a class before you try to code anything.
> You want to violate First Normal Form (1NF). All data values are
> scalar; there are no arrays. Each of those attribures would be a
> separate column.
> Rows are not records; fields are not columns; tables are not files.
> We do not put silly redundant prefixes like "tbl-" on table names.
> Look up ISO-11179.
> I hope you know that IDENTITY cannot be a relational key by definition.
> But you are using a bad thing in the wrong way. It mimics a
> sequential file record number counter without your intervention when
> you declare it as part of the DDL.
> Do you know about check digits, a Regular Expression or some other rule
> to validate your user id?
> SQL is a set-oriented language, so you can insert a query result into a
> base table or updatable VIEW. You are writing SQL like it was a 3GL.
>
> You need a lot more help thanyou can get in a Newsgroup.
>|||>I believe SQL Server 2005 supports arrays
Really?
Roji. P. Thomas
Net Asset Management
http://toponewithties.blogspot.com
"Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> wrote in message
news:%23NDUr8z3FHA.3296@.TK2MSFTNGP09.phx.gbl...
>I believe SQL Server 2005 supports arrays. I'm just getting into it,
>though.
> --
> HTH,
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> A watched clock never boils.
> "--CELKO--" <jcelko212@.earthlink.net> wrote in message
> news:1130887553.702237.72860@.g49g2000cwa.googlegroups.com...
>|||Kevin Spencer (kevin@.DIESPAMMERSDIEtakempis.com) writes:
> I believe SQL Server 2005 supports arrays. I'm just getting into it,
> though.
No, not more than SQL 2000. That is, you can transform a list to table
with a function or similar.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||There are actually two methods to approach this situation. They are:
1. Making use of sp_xml_preparedocument and sp_xml_removedocument and
2. Custom split function (If you want the code snippet for custom split
function .. write back)
Sample table structure:
--
Create table StudentMaster
(
StudentID int IDENTITY(1,1) NOT NULL,
StudentName varchar(100),
StudentAge int
)
Create table StudentDetails
(
StudentID int,
SubjectName varchar(10)
)
Method 1:
--
Create proc InsertStudent
@.StudentName varchar(100),
@.StudentAge int,
@.SubjectString varchar(1000)
AS
Begin Tran StudentTransaction
/* Local Variable Declarations */
Declare @.NewRowId int
Declare @.SubjectXmlDoc int
/* Insert Master record and get identity value */
Insert Into StudentMaster (StudentName, StudentAge) Values (@.StudentName,
@.StudentAge)
-- Retreive the last identity value inserted into the Identity column
(StudentID)
Select @.NewRowId = SCOPE_IDENTITY()
/* Replace dummy identity value with actual id value */
Select @.SubjectString = Replace(@.SubjectString, '123456',
Convert(varchar(10), @.NewRowId))
/* XML Bulk Insert the Subjects */
-- The below line creates XML document and returns numeric ID
Exec sp_xml_preparedocument @.SubjectXmlDoc OUTPUT, @.SubjectString
Insert into StudentDetails (StudentId, SubjectName)SELECT StudentId,
SubjectName FROM OPENXML (@.SubjectXmlDoc, '/root/row') WITH (StudentId int,
SubjectName varchar(100))
-- Deletes the XML document
Exec sp_xml_removedocument @.SubjectXmlDoc
Commit Tran StudentTransaction
/* To test SP */
Exec InsertStudent 'test', 12, '<root><row StudentId="123456"
SubjectName="Maths"/><row StudentId="123456" SubjectName="Science"/></root>'
"David Lozzi" wrote:

> Hello,
> I have some code that adds a new user. The new user has a checkboxlist of
> items which they can be associated with. I would like to send this list of
> items to TSQL along with the new user information. I would guess to combin
e
> the selected items like so: "6,4,8,19,2".
> Kind of do the following:
> INSERT into tblUser (fields) VALUES (data)
> Declare @.userID as integer
> SET @.UserID = @.@.IDENTITY
> for each item in @.Selected
> INSERT into tblSelections (field) VALUE (item, @.UserID)
> I know above isn't exactly possible, but can something similiar be done? I
> dont want to have to run a proc for each item from my asp.net pages...
> Thanks,
> --
> David Lozzi
> Web Applications Developer
> dlozzi@.(remove-this)delphi-ts.com
>
>
>

Sunday, February 19, 2012

Array in expression editor anyone?

I'm kind of a newbie at all this and I'm wondering if I can do the
following. Whithout having to use custom code is there a way to use the IN
function in the expression editor?
I'm currently using the following to accomplish something quite simple:
=IIF((month(Fields!por_POSTING_DATE.Value) = 10 or
month(Fields!por_POSTING_DATE.Value) = 11 or
month(Fields!por_POSTING_DATE.Value) = 12), True,False)
I'd like to use:
=IIF(month(Fields!por_POSTING_DATE.Value) in (10,11,12),True,False)
Can you not use an array in the expression editor (and only in custom code?)
Thanks,
RyanHere's one way to do it:
=iif(Array.BinarySearch(new Integer() {10,11,12},
month(Fields!por_POSTING_DATE.Value))>=0,True,False)
--
This post is provided 'AS IS' with no warranties, and confers no rights. All
rights reserved. Some assembly required. Batteries not included. Your
mileage may vary. Objects in mirror may be closer than they appear. No user
serviceable parts inside. Opening cover voids warranty. Keep out of reach of
children under 3.
"Ryan Opfer" <ropfer@.usa.ibs.org> wrote in message
news:evyaKVzeEHA.2352@.TK2MSFTNGP09.phx.gbl...
> I'm kind of a newbie at all this and I'm wondering if I can do the
> following. Whithout having to use custom code is there a way to use the
IN
> function in the expression editor?
> I'm currently using the following to accomplish something quite simple:
> =IIF((month(Fields!por_POSTING_DATE.Value) = 10 or
> month(Fields!por_POSTING_DATE.Value) = 11 or
> month(Fields!por_POSTING_DATE.Value) = 12), True,False)
> I'd like to use:
> =IIF(month(Fields!por_POSTING_DATE.Value) in (10,11,12),True,False)
> Can you not use an array in the expression editor (and only in custom
code?)
> Thanks,
> Ryan
>|||Thanks Chris that worked great.
Ryan
"Chris Hays [MSFT]" <chays@.online.microsoft.com> wrote in message
news:%23OSa8%23AfEHA.3612@.TK2MSFTNGP12.phx.gbl...
> Here's one way to do it:
> =iif(Array.BinarySearch(new Integer() {10,11,12},
> month(Fields!por_POSTING_DATE.Value))>=0,True,False)
> --
> This post is provided 'AS IS' with no warranties, and confers no rights.
All
> rights reserved. Some assembly required. Batteries not included. Your
> mileage may vary. Objects in mirror may be closer than they appear. No
user
> serviceable parts inside. Opening cover voids warranty. Keep out of reach
of
> children under 3.
> "Ryan Opfer" <ropfer@.usa.ibs.org> wrote in message
> news:evyaKVzeEHA.2352@.TK2MSFTNGP09.phx.gbl...
> > I'm kind of a newbie at all this and I'm wondering if I can do the
> > following. Whithout having to use custom code is there a way to use the
> IN
> > function in the expression editor?
> > I'm currently using the following to accomplish something quite simple:
> >
> > =IIF((month(Fields!por_POSTING_DATE.Value) = 10 or
> > month(Fields!por_POSTING_DATE.Value) = 11 or
> > month(Fields!por_POSTING_DATE.Value) = 12), True,False)
> > I'd like to use:
> > =IIF(month(Fields!por_POSTING_DATE.Value) in (10,11,12),True,False)
> >
> > Can you not use an array in the expression editor (and only in custom
> code?)
> >
> > Thanks,
> >
> > Ryan
> >
> >
>

Monday, February 13, 2012

Arithmetic Overflow Error

I'm getting an overflow error (see ERROR below) when trying to calculate
myPercent (see MY CODE below). I've tried using CAST (see MY CODE below) but
can't get a successful execution. I posted my DDL (see DDL below).
Can someone please help me get over this overflow? I've lost a day trying to
solve this data type problem. I'm sure the proper CAST or CONVERT will solve
the issue, but I'm out of luck and out-of-work until this gets fixed.
Any help would be GREATLY appreciated.
****************
ERROR: Arithmetic overflow error converting numeric to data type numeric.
****************
MY CODE:
SELECT pDate, SUM(pGross) AS SumpGross, SUM(pLoss) AS SumpLoss,
CAST(SUM(CONVERT(decimal(10, 6), p1grade)) /
SUM(CONVERT(decimal(10, 6), pgross - pLoss)) AS DECIMAL(4, 3)) AS myPercent
FROM pPercent
GROUP BY pDate
****************
DDL:
CREATE TABLE [pPercent] (
[pID] [int] IDENTITY (1, 1) NOT NULL ,
[pDate] [datetime] NULL ,
[pShift] [int] NULL ,
[pGross] [int] NULL ,
[pLoss] [int] NULL ,
[p1Grade] [int] NULL
) ON [PRIMARY]
GO
insert into pPercent (pDate, pShift, pGross, pLoss, p1Grade) values
('20051121', '1', '241711', '18525', '24989')
insert into pPercent (pDate, pShift, pGross, pLoss, p1Grade) values
('20051121', '2', '172161', '8268', '22690')
insert into pPercent (pDate, pShift, pGross, pLoss, p1Grade) values
('20051120', '1', '210979', '11487', '21737')decimal(10,6) means 10 digits total, 6 of which are to the right of the
decimal.
e.g., 1234.567890
which only leaves 4 to the left. most of your int values are larger than
this.
change the decimal definition to something large enough - I tend to go
with 10 to the left of the decimal - so decimal(16,6)
Scott wrote:
> I'm getting an overflow error (see ERROR below) when trying to calculate
> myPercent (see MY CODE below). I've tried using CAST (see MY CODE below) b
ut
> can't get a successful execution. I posted my DDL (see DDL below).
> Can someone please help me get over this overflow? I've lost a day trying
to
> solve this data type problem. I'm sure the proper CAST or CONVERT will sol
ve
> the issue, but I'm out of luck and out-of-work until this gets fixed.
> Any help would be GREATLY appreciated.
>
> ****************
> ERROR: Arithmetic overflow error converting numeric to data type numeric.
> ****************
> MY CODE:
> SELECT pDate, SUM(pGross) AS SumpGross, SUM(pLoss) AS SumpLoss,
> CAST(SUM(CONVERT(decimal(10, 6), p1grade)) /
> SUM(CONVERT(decimal(10, 6), pgross - pLoss)) AS DECIMAL(4, 3)) AS myPercen
t
> FROM pPercent
> GROUP BY pDate
> ****************
> DDL:
> CREATE TABLE [pPercent] (
> [pID] [int] IDENTITY (1, 1) NOT NULL ,
> [pDate] [datetime] NULL ,
> [pShift] [int] NULL ,
> [pGross] [int] NULL ,
> [pLoss] [int] NULL ,
> [p1Grade] [int] NULL
> ) ON [PRIMARY]
> GO
>
> insert into pPercent (pDate, pShift, pGross, pLoss, p1Grade) values
> ('20051121', '1', '241711', '18525', '24989')
> insert into pPercent (pDate, pShift, pGross, pLoss, p1Grade) values
> ('20051121', '2', '172161', '8268', '22690')
> insert into pPercent (pDate, pShift, pGross, pLoss, p1Grade) values
> ('20051120', '1', '210979', '11487', '21737')
>
>

Arithmetic operation failure. Is this a bug, or am I doing something wrong?

I used the following code in a function. The @.infloat is input parameter

For every other number than 16.31, 17.31, 18.31, 19.31 and 20.31 (at least those numbers I checked) the code runs ok. For those numbers the result is wrong.

What I want to do is return a ten digits number left filled with zeros, with the last two digits consitered as decimals.

What I do is multiply the given float with 100.00, and take the resulting integer

But when @.infloat is multiplied with 100.00 and @.infloat in (16.31, 17.31, 18.31, 19.31 and 20.31)

the result is (1630,1730,1830,1930,2030) instead of (1631,1731,1831,1931,2031)..

Can anyone try this ?

declare @.ingood int,

@.stuffme varchar(10),

@.infloat float, @.infl float

set @.infloat=18.31

set @.infloat=isnull(@.infloat,0)

set @.stuffme='0000000000'

set @.infl=@.infloat*(100.00)

select @.infl as infl

set @.ingood=cast(@.infl as int)

select @.ingood as ingood

set @.stuffme=stuff(@.stuffme,11-len(@.ingood),len(@.ingood),@.ingood)

select @.stuffme

Replace

set @.ingood=cast(@.infl as int)

WITH

set @.ingood=cast(@.infl as NUMeERIC (10,2))

|||Do you need high precision ? Floating point data is approximate; not all values in the data type range can be precisely represented.

See here :
select convert(float, 18.31)
Result : 18.309999999999999|||

Hi

I have tried MONEY and NUMERIC datatypes for @.infloat and @.infl from your example. They both work just fine.

Arithmetic error

When I run a view, I am getting an SQL (ODBC) error "Arithmetic overflow
error converting real to data type numeric." Below is the line of code in
the view that I think is causing the error (dbo.WorkerTimesheets.PayRate is
a real data type and has a value of 730). Can anyone help me fix it?
Thanks.
CONVERT(varchar(6), CONVERT(decimal(4, 2), dbo.WorkerTimesheets.PayRate)) +
'/' + dbo.PayRateCodes.RateName AS txtPayRate
DavidOf course it overflows. You reserve 4 places for the entire numeric, 2 of
which are decimal places.
730 already takes up 3 places. Add 2 for decimals to that and you get 5.
Give it more room. :) I'd suggest using decimal(12, 2). If this is used to
store wages or salaries, 8 places is more than enough. :)
Spend more time reading BOL.
ML|||Geez! When I said 8 I meant 10. Yes, it's late...|||Do not use CONVERT() when you have CAST(). Never use FLOAT or REAL
unless you know what you are doing. There are all kinds rounding
errors and they display with the 'E' format.
Why are you converting numerics to strings? The first rule of a tiered
architecture is that you never do formatting in the database.
Re-do your pay rates with DECIMAL() data type; you do not bill to 16
decimal places, do you? . Read up on floating point numbers.|||You are all correct. The "overflow" was my brain. When I look at it
now, it makes sense.
David
*** Sent via Developersdex http://www.examnotes.net ***

Sunday, February 12, 2012

are there any MSDE T-SQL code limitations?

I am writing a database app which will run under MSDE on the user's systems.

Other than limitations as to the number of concurrent users, are there any
issues that I need to be aware of when programming the database using SQL
Server 2000? i.e., are there T-SQL programming statements that will run
under SQL Server 2000 as part of my development enviornemnt that won't run
under MSDE on the end users machines, or will MSDE handle anything that SQL
Server can from the database engine standpoint?

Thanks!hi Mike,
"Mike N." <BadDog@.thepound.com> ha scritto nel messaggio
news:r3erb.5780$942.4765@.newssvr25.news.prodigy.co m...
> I am writing a database app which will run under MSDE on the user's
systems.
> Other than limitations as to the number of concurrent users, are there any
> issues that I need to be aware of when programming the database using SQL
> Server 2000? i.e., are there T-SQL programming statements that will run
> under SQL Server 2000 as part of my development enviornemnt that won't run
> under MSDE on the end users machines, or will MSDE handle anything that
SQL
> Server can from the database engine standpoint?

all T-SQL statements SQL Server 2000 supports are supported by MSDE...
you only (only...) have database limitation size, limited replication
support, no mail support...
for further info please visit
http://www.microsoft.com/sql/msde/p...fo/features.asp

hth
Andrea Montanari (Microsoft MVP - SQL Server)
andrea.sql@.virgilio.it
http://www.asql.biz/DbaMgr.shtm http://italy.mvps.org
DbaMgr2k ver 0.4.0 - DbaMgr ver 0.50.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
--- remove DMO to reply