Showing posts with label strsql. Show all posts
Showing posts with label strsql. Show all posts

Monday, March 26, 2012

Executing an string on MS SQL from .Net

Hi there,

I have this:

Dim strSQL As String = "SELECT * FROM GrupoRegistro WHERE Fecha BETWEEN '" & fini & "' AND '" & ffin & "' AND (g.IDTipoCliente = 5) OR g.Fecha BETWEEN '" & fini & "' AND '" & ffin & "' AND (g.IDTipoCliente = 3)"

How do I execute on .Net? I am using VWD2005 Express Edition and MS SQL 2000 server on a WinXp pro with MS Framework 2.0

I am using o trying and some variants :
SelectCommand="@.strsqlvar">
<SelectParameters>
<asp:QueryStringParameter Name="strsqlvar" DefaultValue="strsql.string" />
</SelectParameters>

And it doesn′t work... any help will e well apreciated. thank u in advance.

Lesson number "8" here might help:

http://msdn.microsoft.com/vstudio/express/sql/learning/default.aspx

Executing an string on MS SQL from .Net

Hi there,

I have this:

Dim strSQL As String = "SELECT * FROM GrupoRegistro WHERE Fecha BETWEEN '" & fini & "' AND '" & ffin & "' AND (g.IDTipoCliente = 5) OR g.Fecha BETWEEN '" & fini & "' AND '" & ffin & "' AND (g.IDTipoCliente = 3)"

How do I execute on .Net? I am using VWD2005 Express Edition and MS SQL 2000 server on a WinXp pro with MS Framework 2.0

I am using o trying and some variants :
SelectCommand="@.strsqlvar">
<SelectParameters>
<asp:QueryStringParameter Name="strsqlvar" DefaultValue="strsql.string" />
</SelectParameters>

And it doesn′t work... any help will e well apreciated. thank u in advance.

Lesson number "8" here might help:

http://msdn.microsoft.com/vstudio/express/sql/learning/default.aspx

sql

Wednesday, March 7, 2012

execute scalar question

Im using the following code in my application. Is it redundent to add the "Top 1" to the select or does it help performance? Thanks

string strSQL ="SELECT TOP 1 c.CusId " +"FROM COCUS c " +"LEFT JOIN CONOTITM n ON c.NotId = n.NotId " +"WHERE c.CusId NOT IN(SELECT CusId FROM RDK_PROSPECT_LOCK WHERE EmpId <> '" + USER.ID() +"') " +"ORDER BY n.DateUpdate, c.DateUpdate ASC";string strCusID = RDK.DATA.ReturnScalar(strSQL);
If your query can only ever return one row then it won't be necessary. If it can return more than one row then adding the Top 1 would probably help as otherwise you would be sending back multiple rows that would then be discarded apart from the first column in the first row. If optimum efficiency is what you are after I'd suggest using a stored procedure with an output parameter if you only need to return one value.|||

Yes, it will help performance. Not only does it guarantee that only a single row will be returned, but it also allows SQL Server to optimize it's query.

It's similiar to asking "Get me the lowest..." and "Get me all of them and order them by...". The first one allows SQL Server to look for the lowest and once it finds it, then stop.