Showing posts with label cant. Show all posts
Showing posts with label cant. Show all posts

Wednesday, March 28, 2012

MAX dont know what type is returning

Hi guys,

I'm doing some function in the SQLExpress using the max func and I cant figure out if its returning null or empty string. It always return null even it's returning index.

Please help.

Here's is the sample data of the table that I'm manipuilating

code name

code name

code_1 name_1

code_2 name_2

tues_2 name_4

code_4 name_3

>>> What am trying to get is the maximum index of the code

Below is my function

declare @.codeIndex varchar(20)

select @.codeIndex = isnull(max(isnull(substring([code],len('code')+2), len'code')) ,0)),0) from table where [code] like 'code%'

print @.codeIndex

if @.codeIndex is null

begin

print 'Code index is null

end

else

begin

print 'we got an index!'

end

>>> the output of this is always null even it's returning an index

Can you post a full repro? You code didn't compile (not correct number of parameters etc). Either against the pubs database or also post CREATE TABLE and some INSERT statements. I changed the code so it at least compiled (but I doubt it has correct logic), and there doesn't seem to anything wrong with the MAX function per se.: declare @.codeIndex varchar(20) select @.codeIndex = isnull(max(isnull(substring([au_lname],len('code')+2, len('code')) ,0)),0) from authors print @.codeIndex if @.codeIndex is null begin print 'Code index is null' end else begin print 'we got an index!' end -- Tibor Karaszi, SQL Server MVP http://www.karaszi.com/sqlserver/default.asp http://www.solidqualitylearning.com/ Blog: http://solidqualitylearning.com/blogs/tibor/ wrote in message news:b4844e9a-27a2-49d0-8a11-482daa3423db@.discussions.microsoft.com...
> Hi guys, >
> I'm doing some function in the SQLExpress using the max func and I
> cant figure out if its returning null or empty string. It always return
> null even it's returning index. >
> Please help. >
> Here's is the sample data of the table that I'm manipuilating >
> code name >
> code name >
> code_1 name_1 >
> code_2 name_2 >
> tues_2 name_4 >
> code_4 name_3 > > > >>>> What am trying to get is the maximum index of the code >
> Below is my function >
> declare @.codeIndex varchar(20) >
> select @.codeIndex = isnull(max(isnull(substring([code],len('code')+2),
> len'code')) ,0)),0) from table where [code] like 'code%' > > >
> print @.codeIndex >
> if @.codeIndex is null >
> begin >
> print 'Code index is null >
> end >
> else >
> begin >
> print 'we got an index!' >
> end > >>>> the output of this is always null even it's returning an index >
>|||

Hi NNTP,

Thanks! I already figured it out; maybe, I'm just exhausted last friday.

Saturday, February 25, 2012

Master-Detail w/Gridview-DetailsView Stored Procedure Problem

I am attempting to setup a Master-Details with GridView/DetailsView but I can't seem to find any information on using a stored procedure that requires parameters with the SqlDataSource control.

SelectCommandType specifies that you are using a stored proc. SelectCommand specifies the name of the proc, but I haven't found any information on how to pass a parameter to the stored procedure.

Is it even possible or do I have to forget about using the DetailsView control altogether?

you should use an sql parameter like this in your sql data source:

here a dropdown list value is taken as a parameter:

<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:urConnString %>"

SelectCommand="urSP"SelectCommandType="StoredProcedure"EnableCaching="True">

<SelectParameters>

<asp:ControlParameterControlID="dropdown"Name="urparamname"PropertyName="SelectedValue"

Type="String"/>

</SelectParameters>

</asp:SqlDataSource>

hope this helps.

|||

Thanks Raj, but I have already done that. My code, as you suggested, looks like this:

<asp:SqlDataSource ID="DetailsViewSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ForexturtleConnectionString %>"
DeleteCommand="swsp_DeleteCompany" DeleteCommandType="StoredProcedure" InsertCommand="swsp_InsertCompany"
InsertCommandType="StoredProcedure"SelectCommand="swsp_GetCompany" SelectCommandType="StoredProcedure"
UpdateCommand="swsp_UpdateCompany" UpdateCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="swCompanyId" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>

The stored procedure (swsp_GetCompany) requires the record ID as a parameter to grab the correct record. It works great against the database. GridView1 had previously selected the correct record, but I don't see how it supplies swCompanyId to DetailsViewSqlDataSource:


<asp:SqlDataSource ID="GridViewSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ForexturtleConnectionString %>"
SelectCommand="swsp_GetCompanies" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="swCompanyId" DataSourceID="GridViewSqlDataSource">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="swCompanyId" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="swCompanyId" />
<asp:BoundField DataField="swName" HeaderText="Company" SortExpression="swName" />
</Columns>
</asp:GridView>

I still get an error that says, "Procedure or function 'swsp_GetCompany' expects parameter '@.id', which was not supplied."



|||

I am not sure as how to pass the value from a gridview to detailsview as a parameter...

one thing u can check is the name of the parameter... if u have used "@.id" in ur SP, then try to use the same name from .aspx page also...but here u r passing 'swcompanyID' which is not expected by the SP...

<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="swCompanyId" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>

hope this helps you...

|||

Thanks so much for your help! As it turned out, I modified the name of the parameter in the stored procedure from @.id to @.swCompanyId and everything worked great. Thanks again for your help.

Monday, February 20, 2012

master.dbo.spt_values

Hello,
Can anybody explain me this table or can send one link
where i can get this information. This table look likes
very important but i cant find a good explanation of it.
Best regards
I don't think spt_values is officially documented in any of
Microsoft's documentation. It's mentioned in some articles
and books - you can find some information in this article:
http://www.winnetmag.com/SQLServer/A...8415/8415.html
and this FAQ post:
http://www.mssqlserver.com/faq/general-sptvalues.asp
It's essentially just a large lookup table used by SQL
Server functions, stored procedures, etc.
-Sue
On Tue, 6 Jul 2004 05:37:05 -0700, "CC&JM"
<anonymous@.discussions.microsoft.com> wrote:

>Hello,
>Can anybody explain me this table or can send one link
>where i can get this information. This table look likes
>very important but i cant find a good explanation of it.
>Best regards
|||This is an undocumented table, for SQL Server's internal use. What is it
that you are after? You can look at the code of system sps that use this
table.
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
Is .NET important for a database professional?
http://vyaskn.tripod.com/poll.htm
"CC&JM" <anonymous@.discussions.microsoft.com> wrote in message
news:2739701c46355$f1f742a0$a401280a@.phx.gbl...
Hello,
Can anybody explain me this table or can send one link
where i can get this information. This table look likes
very important but i cant find a good explanation of it.
Best regards

master.dbo.spt_values

Hello,
Can anybody explain me this table or can send one link
where i can get this information. This table look likes
very important but i cant find a good explanation of it.
Best regardsI don't think spt_values is officially documented in any of
Microsoft's documentation. It's mentioned in some articles
and books - you can find some information in this article:
http://www.winnetmag.com/SQLServer/.../8415/8415.html
and this FAQ post:
http://www.mssqlserver.com/faq/general-sptvalues.asp
It's essentially just a large lookup table used by SQL
Server functions, stored procedures, etc.
-Sue
On Tue, 6 Jul 2004 05:37:05 -0700, "CC&JM"
<anonymous@.discussions.microsoft.com> wrote:

>Hello,
>Can anybody explain me this table or can send one link
>where i can get this information. This table look likes
>very important but i cant find a good explanation of it.
>Best regards|||This is an undocumented table, for SQL Server's internal use. What is it
that you are after? You can look at the code of system sps that use this
table.
--
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
Is .NET important for a database professional?
http://vyaskn.tripod.com/poll.htm
"CC&JM" <anonymous@.discussions.microsoft.com> wrote in message
news:2739701c46355$f1f742a0$a401280a@.phx
.gbl...
Hello,
Can anybody explain me this table or can send one link
where i can get this information. This table look likes
very important but i cant find a good explanation of it.
Best regards

master.dbo.spt_values

Hello,
Can anybody explain me this table or can send one link
where i can get this information. This table look likes
very important but i cant find a good explanation of it.
Best regardsI don't think spt_values is officially documented in any of
Microsoft's documentation. It's mentioned in some articles
and books - you can find some information in this article:
http://www.winnetmag.com/SQLServer/Article/ArticleID/8415/8415.html
and this FAQ post:
http://www.mssqlserver.com/faq/general-sptvalues.asp
It's essentially just a large lookup table used by SQL
Server functions, stored procedures, etc.
-Sue
On Tue, 6 Jul 2004 05:37:05 -0700, "CC&JM"
<anonymous@.discussions.microsoft.com> wrote:
>Hello,
>Can anybody explain me this table or can send one link
>where i can get this information. This table look likes
>very important but i cant find a good explanation of it.
>Best regards|||This is an undocumented table, for SQL Server's internal use. What is it
that you are after? You can look at the code of system sps that use this
table.
--
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
Is .NET important for a database professional?
http://vyaskn.tripod.com/poll.htm
"CC&JM" <anonymous@.discussions.microsoft.com> wrote in message
news:2739701c46355$f1f742a0$a401280a@.phx.gbl...
Hello,
Can anybody explain me this table or can send one link
where i can get this information. This table look likes
very important but i cant find a good explanation of it.
Best regards