Showing posts with label explain. Show all posts
Showing posts with label explain. Show all posts

Monday, March 26, 2012

PROBLEM REGARDING VARIABLE PASSING TO STORED PROCEDURE

Hi

I am WORKING IN AN APPLICATION USING SQL SERVER 2000 AND VB6

I'VE A PROBLEM REGARDING VARIABLE PASSING TO STORED PROCEDURE

I WILL EXPLAIN WITH AN EXAMPLE

TABLE STRUCTURE

AccAccounts

Accid(Numeric) AccName(Varchar)

-

1 Cash A/c

2 Students A/c

3 HDFC Bank A/c

my Application will pass the "Accid" as a string format to Stored Procedure

STORED PROCEDURE

--

CREATE PROCEDURE GetAccName
@.Accid Varchar(100)
AS
Select * from Accaccount where accid in (@.Accid)

when i run this SP

declare @.Accid Varchar(100)
set @.Accid ='1,2'

exec GetAccName @.Accid

i get the following error

Server: Msg 8114, Level 16, State 5, Procedure GetAccName, Line 4
Error converting data type varchar to numeric.

please "ANY ONE" help me!!.

The above example is only an example

REGARDS

JAMES

Hi,

You can not use the @.Variable which holds the multiple accountids in Static SQL statement.. you need to use dynamic sql..

Code Snippet

CREATE PROCEDURE GetAccName
@.Accid Varchar(100)
AS
Declare @.cmd varchar(4000)

Set @.Cmd = 'Select * from Accaccount where accid in (' + @.Accid')'

exec (@.cmd)

But would suggest you to go through the following link to see the advantages and disadvantages..

http://www.sommarskog.se/dynamic_sql.html

Regards,

|||

You can also do this without dynamic sql.

Code Snippet

CREATE PROCEDURE GetAccName
@.Accid Varchar(100)
AS
Select *
from AccAccounts
where charindex(','+convert(varchar,accid)+',',','+@.Accid+',')>0

|||

THANK U VERY MUCH

|||

Hi James

You shouldn't pass comma separated values to the stored procedure, like: '1,2,3' . Because when you call the sproc it is trying to convert your value(because accid is numeric in your table) to varchar implicitly and due to the ',' in your data the conversion is going to fail and throws an error. You need to write some other logic to get it done.

Thanks & Regards,

Kiran.Y

|||

HI

THX FOR REPLY

WHAT IN CASE IF I NEED A QRY

Select * from AccAccounts where Accid Not in (1,2)

|||

>0 means a match is found

=0 means no match.

Code Snippet

CREATE PROCEDURE GetAccName
@.Accid Varchar(100)
AS
Select *
from AccAccounts
where charindex(','+convert(varchar,accid)+',',','+@.Accid+',') = 0

|||

Thx

Wednesday, March 21, 2012

Problem performing a join on a function in a SQL query

Hello,

Can someone explain why this code contains the following error:

Msg 4104, Level 16, State 1, Line 2

The multi-part identifier "TheTable.StartValue" could not be bound.

CREATE FUNCTION MyFunction(@.StartValue int)

RETURNS @.MyTable TABLE

(

NextValue int NOT NULL

)

AS

BEGIN

INSERT INTO @.MyTable(NextValue)

VALUES (@.StartValue + 1)

INSERT INTO @.MyTable(NextValue)

VALUES (@.StartValue + 2)

RETURN

END

GO

CREATE TABLE TheTable

(

StartValue int NOT NULL

)

GO

INSERT INTO TheTable(StartValue)

VALUES (10)

INSERT INTO TheTable(StartValue)

VALUES (20)

GO

SELECT *

FROM TheTable CROSS JOIN

MyFunction(TheTable.StartValue)

You can′t do that per row. The logic is quite simple that you presented here, what about doing

SELECT StartValue, StartValue+1,StartValue+2
From SomeTable

HTH, Jens Suessmeyer.

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

In SQL Server 2000, this is not possible. However, in 2005, you can use the CROSS APPLY join operator:

SELECT *
FROM TheTable
CROSS APPLY MyFunction(TheTable.StartValue)

Interesting function. If you don't mind, could you share the purpose?

|||

Hi,

you cannot use Table's Column as a parameter to the function. Only variables or Static Literals can be passed as an argument to the function

|||

Thanks for your reply.

I wrote that function as an example of what I was trying to do. I have a vertical bar delimited column (eg. this|is|my|column). I used a CLR function to get all the values. I then run a aggregate of these values based on another field in another table. So the output should be something like this.

this: 2
is: 4
my: 0
column: 1

I can't do a straight aggregate because the "my" values above would be omitted.

|||

Thanks for your reply.

I wrote that function as an example of what I was trying to do. I have a vertical bar delimited column (eg. this|is|my|column). I used a CLR function to get all the values. I then run a aggregate of these values based on another field in another table. So the output should be something like this.

this: 2
is: 4
my: 0
column: 1

I can't do a straight aggregate because the "my" values above would be omitted.

Tuesday, March 20, 2012

Problem on report designer

Hi all.

I have the problem on showing the records in my report.
I explain how i designed the report. I made the report in Business Intelligence Project. The report I am achieving is the Personal Information of all employees.
After creating a query/dataset, I dragged the fields to the textboxes. I am trying to show 1 employees' record in each page.
My report looks like this...

EMPLOYEES PERSONAL INFORMATION

Employee Name : <There is a photo Image here>
Age : _
Address: _
Telephone #:_
Province:_
BirthPlace:__
Birthdate:

Gender:__WEIGHT:_
Civil Status:__Height:_
Relgion:_Hair Color:_
Nationality:Eye Color:__

IN CASE OF EMERGENCY PLEASE CONTACT
Name:_
Address:_
telephone:__

EDUCATIONAL BACKGROUND
EDUCATIONAL LEVEL.......SCHOOL.....FROM-TO......DEGREE
Elementary..............Harvard....1990-1992
High School.............LaSalle....1992-1995
College.................UP.........1995-2000

__
Run Time: 2/3/2007
Page No. : 1

I used dot above just for spacing and alignment but not included in my actual report.

I used table for EDUCATIONAL BACKGROUD.

My problem is: when i ran the report, it can't automatically creates report for all employees. It only shows the first employee in the database.

Any suggestions and guidance please.

Thanks.
-Ron-

You say you are using textboxes... Are these textboxes in a List control or the Details section of a Table control?

BobP

|||

its on the list control. I only used table in EDUCATIONAL BACKGROUND.... Is it possible to show all the records in textboxes(on the list control)? If not, any suggestion of how could I design this report...

thanks.

-Ron-

|||

I think you should put all the information in your table.

You will have a detail row for each row on your page. For example:

Detail Row 1: EMPLOYEES PERSONAL INFORMATION
Detail Row 2:
Detail Row 3: Employee Name : __
Detail Row 4: Age : __
...
...
Detail Row v: EDUCATIONAL BACKGROUND
Detail Row w: EDUCATIONAL LEVEL.......SCHOOL.....FROM-TO......DEGREE
Detail Row x: Elementary..............Harvard....1990-1992
Detail Row y: High School.............LaSalle....1992-1995
Detail Row z: College.................UP.........1995-2000

Instead of putting spaces in there to make them align, I would have the SCHOOL, FROM-TO, and DEGREE in their own columns.

Hope this helps.

Jarret

|||

If table is the only solution for this. Ok, i have to use it... If there is any suggestion please tell me.

Thanks.

-Ron-

|||

EMPLOYEES PERSONAL INFORMATION

Employee Name : <There is a photo Image here>
Age : _
Address: _
Telephone #:_
Province:_
BirthPlace:__
Birthdate:

Gender:__WEIGHT:_
Civil Status:__Height:_
Relgion:_Hair Color:_
Nationality:Eye Color:__

IN CASE OF EMERGENCY PLEASE CONTACT
Name:_
Address:_
telephone:__

EDUCATIONAL BACKGROUND
EDUCATIONAL LEVEL SCHOOL FROM-TO DEGREE
Elementary Harvard 1990-1992 BSCS
High School LaSalle 1992-1995 BSIT
College UP 1995-2000 BSIT

__
Run Time: 2/3/2007
Page No. : 1

The report above is my expected result of my report. Until now dont get it yet. Could someone help me please. I have the problem on displaying the EDUCATIONAL BACKGRUND. EDUCATIONAL BACKGRUND of a person is dynamically created.

My table in EDUCATIONAL BACKGRUND

empno educlevel school fromto degree

1 elementary UP 2001-2002 BSCS
1 high school UP 2001-2002 BSCS
1 college UP 2001-2002 BSCS
2 elemntary UP 2001-2002 BSCS
2 college UP 2001-2002 BSCS
3 elem UP 2001-2002 BSCS
3 high UP 2001-2002 BSCS
3 college UP 2001-2002 BSCS
3 master UP 2001-2002 BSCS

I tried to use only 1 table for my whole report but i need to group the EDUCATION BACKGROUND. and the group appears in the first row of the table. How could i set the group to the last row? please guide me of what i am doing if it is correct or not. Thanks.

2nd option i tried. I used different table for EDUCATION but it will occur vry bad output.

-Ron-

|||

Hello Ron,

You will need to setup your report to group by empno, then the detail row would show the educlevel, school, fromto, and degree. The group header section is where you will need to place all of the 'static' report information (everything down to where the education levels are listed). You can then right-click on your group header and select 'Insert Row Below' and keep doing this for every row in your report (up to the education levels). It should look something like this:

Group Header Row 1: EMPLOYEES PERSONAL INFORMATION
Group Header Row 2:
Group Header Row 3: Employee Name : __
Group Header Row 4: Age : __
...
...
Group Header Row y: EDUCATIONAL BACKGROUND
Group Header Row z: EDUCATIONAL LEVEL.......SCHOOL.....FROM-TO......DEGREE
Detail Row 1: Fields!educlevel.Value...Fields!school.Value...Fields!fromto.Value...Fields!degree.Value

Hope this helps.

Jarret

|||

Thanks Jarret...i appreciate your help... :)

-Ron-

Problem on report designer

Hi all.

I have the problem on showing the records in my report.
I explain how i designed the report. I made the report in Business Intelligence Project. The report I am achieving is the Personal Information of all employees.
After creating a query/dataset, I dragged the fields to the textboxes. I am trying to show 1 employees' record in each page.
My report looks like this...

EMPLOYEES PERSONAL INFORMATION

Employee Name : <There is a photo Image here>
Age : _
Address: _
Telephone #:_
Province:_
BirthPlace:__
Birthdate:

Gender:__WEIGHT:_
Civil Status:__Height:_
Relgion:_Hair Color:_
Nationality:Eye Color:__

IN CASE OF EMERGENCY PLEASE CONTACT
Name:_
Address:_
telephone:__

EDUCATIONAL BACKGROUND
EDUCATIONAL LEVEL.......SCHOOL.....FROM-TO......DEGREE
Elementary..............Harvard....1990-1992
High School.............LaSalle....1992-1995
College.................UP.........1995-2000

__
Run Time: 2/3/2007
Page No. : 1

I used dot above just for spacing and alignment but not included in my actual report.

I used table for EDUCATIONAL BACKGROUD.

My problem is: when i ran the report, it can't automatically creates report for all employees. It only shows the first employee in the database.

Any suggestions and guidance please.

Thanks.
-Ron-

You say you are using textboxes... Are these textboxes in a List control or the Details section of a Table control?

BobP

|||

its on the list control. I only used table in EDUCATIONAL BACKGROUND.... Is it possible to show all the records in textboxes(on the list control)? If not, any suggestion of how could I design this report...

thanks.

-Ron-

|||

I think you should put all the information in your table.

You will have a detail row for each row on your page. For example:

Detail Row 1: EMPLOYEES PERSONAL INFORMATION
Detail Row 2:
Detail Row 3: Employee Name : __
Detail Row 4: Age : __
...
...
Detail Row v: EDUCATIONAL BACKGROUND
Detail Row w: EDUCATIONAL LEVEL.......SCHOOL.....FROM-TO......DEGREE
Detail Row x: Elementary..............Harvard....1990-1992
Detail Row y: High School.............LaSalle....1992-1995
Detail Row z: College.................UP.........1995-2000

Instead of putting spaces in there to make them align, I would have the SCHOOL, FROM-TO, and DEGREE in their own columns.

Hope this helps.

Jarret

|||

If table is the only solution for this. Ok, i have to use it... If there is any suggestion please tell me.

Thanks.

-Ron-

|||

EMPLOYEES PERSONAL INFORMATION

Employee Name : <There is a photo Image here>
Age : _
Address: _
Telephone #:_
Province:_
BirthPlace:__
Birthdate:

Gender:__WEIGHT:_
Civil Status:__Height:_
Relgion:_Hair Color:_
Nationality:Eye Color:__

IN CASE OF EMERGENCY PLEASE CONTACT
Name:_
Address:_
telephone:__

EDUCATIONAL BACKGROUND
EDUCATIONAL LEVEL SCHOOL FROM-TO DEGREE
Elementary Harvard 1990-1992 BSCS
High School LaSalle 1992-1995 BSIT
College UP 1995-2000 BSIT

__
Run Time: 2/3/2007
Page No. : 1

The report above is my expected result of my report. Until now dont get it yet. Could someone help me please. I have the problem on displaying the EDUCATIONAL BACKGRUND. EDUCATIONAL BACKGRUND of a person is dynamically created.

My table in EDUCATIONAL BACKGRUND

empno educlevel school fromto degree

1 elementary UP 2001-2002 BSCS
1 high school UP 2001-2002 BSCS
1 college UP 2001-2002 BSCS
2 elemntary UP 2001-2002 BSCS
2 college UP 2001-2002 BSCS
3 elem UP 2001-2002 BSCS
3 high UP 2001-2002 BSCS
3 college UP 2001-2002 BSCS
3 master UP 2001-2002 BSCS

I tried to use only 1 table for my whole report but i need to group the EDUCATION BACKGROUND. and the group appears in the first row of the table. How could i set the group to the last row? please guide me of what i am doing if it is correct or not. Thanks.

2nd option i tried. I used different table for EDUCATION but it will occur vry bad output.

-Ron-

|||

Hello Ron,

You will need to setup your report to group by empno, then the detail row would show the educlevel, school, fromto, and degree. The group header section is where you will need to place all of the 'static' report information (everything down to where the education levels are listed). You can then right-click on your group header and select 'Insert Row Below' and keep doing this for every row in your report (up to the education levels). It should look something like this:

Group Header Row 1: EMPLOYEES PERSONAL INFORMATION
Group Header Row 2:
Group Header Row 3: Employee Name : __
Group Header Row 4: Age : __
...
...
Group Header Row y: EDUCATIONAL BACKGROUND
Group Header Row z: EDUCATIONAL LEVEL.......SCHOOL.....FROM-TO......DEGREE
Detail Row 1: Fields!educlevel.Value...Fields!school.Value...Fields!fromto.Value...Fields!degree.Value

Hope this helps.

Jarret

|||

Thanks Jarret...i appreciate your help... :)

-Ron-