Showing posts with label syntax. Show all posts
Showing posts with label syntax. Show all posts

Friday, February 24, 2012

Checking that an object is not empty

Hi,

Does anyone know the correct syntax to check the contents of an object variable. I want to do this as part of a constraint,

TIA

R

Variables of type Object are not support in expressions -

"The data type of variable "User::Variable" is not supported in an expression."

|||

Thanks for your reply.

I have a problem then. I want to pass in this object to use in an ExecuteSQL task, as my input parameter. However, because of some conditional execution, there may not be anything to update. This means that the object has nothing in it, and at the moment. This is causing my task to fail.

Any ideas?

|||

You could read the object variable inside a script task, and check for it equalling Nothing.

Then set a boolean variable indicating whether it is populated or not and put an expression on the precedence constraint that checks the boolean variable to see whether it should execute or not.

-Jamie

checking report expression syntax

Hello!

I have a report that I am writing that was displaying perfectly, until I had to add in group totals and "sum" some of the expressions. When I did that for some reason it over rode the "format percent" part of the expresson and is no longer "formatting as a percent"

Any tips of where I could go to get my syntax in order?

Any help would be appriciated!!

If you can, post the expression that you are using.

One quick idea is that for the format string to work, you need to have your expression return the correct type. For example, if your expression returns a string and you are formatting a float as a percent, it isn't going to work.

|||

This is one of the expressions Im using :

Sum(Val(FormatPercent((Fields!ID30_DaysCNT.Value/Fields!TOTAL_UPB_CNT.Value),0)))

This among many other things in this report are making me crazy!!

Thanks for any input :)

|||

try moving the FormatPercent to the outside of the sum expression:

FormatPercent(Sum(Fields!ID30_DaysCNT.Value/Fields!TOTAL_UPB_CNT.Value))

|||Ok that actually worked....awesome thanks!!|||But wait, what about the Val() that needs to go in there ? how do I do it with that ?|||I thought you said it works now. Is there a reason you need to use the Val function?|||It did work until I got towards the end of the document.....I need the Val because sporatically throughout my report there are NAN and Infinity's ...but sometimes the Zero's do show through ....

Thursday, February 16, 2012

Checking for NULL within an Expression

Hi All,

I would like an example of checking for NULL within an expression. I don't know the correct syntax. Checking for IsNull is incorrect so is IS Null. Can anyone help me?

Another C#er!

Try if(IsNothing(Myvalue)) or if(Myvvalue = Nothing)

hth

Helen

|||

Read this post, it should help

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1248764&SiteID=1

Tuesday, February 14, 2012

CHECKDB table exclusion ?

Hi There

I have checked CHECKDB syntax in BOL, i just want to be sure.

In there no way to run CHECKDB on a user database and exclude certain tables, in SS2000.

I have 2 really huge tables , over a billion rows. Nightly i want to run CHECKDB on the database but i do NOT want CHECKTABLE run on these 2 tables as it takes hours.

Or is my only option to instead of running CHECKDB, writing a script that loops through user tables excluding these and running CHECKTABLE. If this is my only option can it be done with a cursor looping through user tables and running CHECKTABLE on each one?

Thanx

Your only option is to run CHECKTABLE with the specific tables. CHECKDB doesn't have any option to filter tables.

Sunday, February 12, 2012

Check the syntax

I'm getting the following error messages:
Incorrect syntax near the keyword 'in'.
Server: Msg 156, Level 15, State 1, Line 38
Incorrect syntax near the keyword 'group'.

/* create temp tables */
select distinct d_vst_id as 'DRW_ID'
,d_vst_instid as 'DRW_INSTID'
into temp_tb1
from dnr_vst_db_rec
where d_vst_instid = ''
and d_vst_dontyp = 'WB'
and d_vst_status = 'DN'
and d_vst_date between 20020301 and 20030228
order by d_vst_id

Select distinct
n_per_id as 'ID1'
,n_per_gender as 'GENDER'
,n_per_birth as 'BIRTH1'
,d_bty_abo + d_bty_rhesus as 'ABO1'
,n_adr_city as 'CITY1'
,n_adr_zip as 'ZIP1'
into temp_tb3
from temp_tb1 right outer join nat_per_db_rec
on DRW_ID = n_per_id
right outer join dnr_bty_db_rec
on DRW_ID = d_bty_id
right outer join nat_adr_db_rec
on DRW_ID = n_adr_id
where DRW_INSTID = ''
order by n_per_id

select distinct getdate()
,d_aaa_insthdg
, case (d_vst_btcdte - n_per_birth) / 10000
when in (14,15,16) the '14-16'
when in (17,18,19,20) then '17-20'
when in (21, 22,23,24,25) then '21-25'
when in (26,27,28,29,30) then '26-30'
when in (31,32,33,34,35) then '31-35'
when in (36,37,38,39,40) then '36-40'
when in (41,42,43,44,45) then '41-45'
when in (46,47,48,49,50) then '46-50'
when in (51,52,53,54,55) then '51-55'
when in (56,57,58,59,60) then '56-60'
when in (61,62,63,64,65) then '61-65'
when in (66,67,68,69,70) then '66-70'*/
else
71+
end as 'AGE'
,sum(case a.d_vst_dontyp when '1' then 1 else 0 end ) as 'DRAW1'
,sum(case a.d_vst_dontyp when 'xx' then 1 else 1 end ) as 'TOTAL'
from dnr_aaa_db_rec, dnr_dud_db_rec, temp_tb3, dnr_vst_db_rec a
where a.d_vst_instid = ''
and a.d_vst_instid = d_aaa_instid
and a.d_vst_id = ID1
and a.d_vst_instid = n_per_instid
and a.d_vst_id = n_per_id
and n_per_gender = 'M'
and a.d_vst_btcdte between 20020301 and 20030228
and a.d_vst_btcdte = (Select max(b.d_vst_btcdte)
from dnr_vst_db_rec b
where b.d_vst_instid = ''
and b.d_vst_status = 'DN'
and b.d_vst_dontyp = 'WB'
and b.d_vst_id = a.d_vst_id
and b.d_vst_btcdte between 20020301 and 20030228)

group by
d_aaa_insthdg
,case (d_vst_btcdte - n_per_birth) / 10000
when in (14,15,16) the '14-16'
when in (17,18,19,20) then '17-20'
when in (21, 22,23,24,25) then '21-25'
when in (26,27,28,29,30) then '26-30'
when in (31,32,33,34,35) then '31-35'
when in (36,37,38,39,40) then '36-40'
when in (41,42,43,44,45) then '41-45'
when in (46,47,48,49,50) then '46-50'
when in (51,52,53,54,55) then '51-55'
when in (56,57,58,59,60) then '56-60'
when in (61,62,63,64,65) then '61-65'
when in (66,67,68,69,70) then '66-70'*/
else
71+
end asI think you have 2 problems. First, move (d_vst_btcdte - n_per_birth) / 10000 to be between "when" and "in". Second, in both case statements you have 71+ followed by "*/". You need to surround 71+ with apostrophes and remove */.

Friday, February 10, 2012

Check syntax in EM

Hello,
The "check syntax" under database->stored procedures in
the SQL 2K EM does not check the objects correctly when
you create/alter an SP. Always says "successful" even if
the table does not exists. Is this a bug?
SQL2K + SP3 on Win2003 Standard.
Thanks
Dennis
Object names referenced in an SP aren't resolved until the SP is compiled,
which means the first time it runs not when it is created. You need to test
the SP by calling it. Not a bug, although many people don't like this
feature.
David Portas
SQL Server MVP

Check syntax in EM

Hello,
The "check syntax" under database->stored procedures in
the SQL 2K EM does not check the objects correctly when
you create/alter an SP. Always says "successful" even if
the table does not exists. Is this a bug?
SQL2K + SP3 on Win2003 Standard.
Thanks
DennisObject names referenced in an SP aren't resolved until the SP is compiled,
which means the first time it runs not when it is created. You need to test
the SP by calling it. Not a bug, although many people don't like this
feature.
--
David Portas
SQL Server MVP
--

Check syntax in EM

Hello,
The "check syntax" under database->stored procedures in
the SQL 2K EM does not check the objects correctly when
you create/alter an SP. Always says "successful" even if
the table does not exists. Is this a bug?
SQL2K + SP3 on Win2003 Standard.
Thanks
DennisObject names referenced in an SP aren't resolved until the SP is compiled,
which means the first time it runs not when it is created. You need to test
the SP by calling it. Not a bug, although many people don't like this
feature.
David Portas
SQL Server MVP
--

Check SQL syntax

First of all, hello and good morning, my question is, you can check SQL syntax in SQL Server with secondary button mouse or "Check SQL" button in toolbar (Microsoft Management Console 1.2).
Id like to know if theres a way to use these Server tools from Visual Basic 6 SP6, something like APIs ...
If theres no solution, can anybody give me an idea of how to check SQL syntax in VB.
The application wants the users to make their own SQL sentences, (they just can write whatever they want ???)Ive solved it with transactions, commit and rollback.
Thanks for your patience|||Hi pucca,

Could u kindly explain how u done it. Atleast briefly when u r free...

thnks in advance

With regards
Sudar|||because I noticed that I hadnt to check the sintax, I just had to wait VB would do the SQL Statement, if it couldnt do it then the sentence the user wrote was wrong or there were constraints in the server side.
Sorry for my english, Ill try to explain the situation.
The application has a form called frmConsultasCampanya where the users can see the stored consults and manage them (add new, delete, modify ...), the users just write the consult as they need, so we can find some consults that return the same results, and as these data are stored in other table the application can stop execution. My idea was to check the consult before its execution, and if everything was right execute it, but I realized that I could check the syntax, not the logica.
I had heard of transactions, and I discovered you could do it in vb 6.
My solution is the following:

Public Function ejecutar_consulta() As Long
Dim cmd As Command
Dim rs As Recordset
Dim rs_2 As Recordset
Dim cont As Long
Dim ident_pers As Long
Dim encontrado As Boolean
Dim habilitado As Boolean
Dim sql As String

Set cmd = New Command
Set cmd.ActiveConnection = cn

'En primer lugar, antes de ejecutar nada ver si esa consulta ya se ha procesado para
'esa campaa. Si se ha procesado ya, se sale de la funcion, devolviendo el valor -1
'para que se pueda mostrar un mensaje adecuado indicando que la consulta ya se ha
'ejecutado.
cmd.CommandText = "select * from Consultas_campanya where Id_Campanya = '" & Campanya & "' and Id_Consulta = '" & Ident_Consulta & "' and habilitado=1"
Set rs = cmd.Execute
If Not rs.EOF Then
'Ya se ha procesado esta consulta para esta campaa, salir de la funcion
ejecutar_consulta = -1
Exit Function
End If

cmd.CommandText = Consulta_SQL
'Set rs = cmd.Execute '(1)

'------INICIO BARRA DE PROGRESO
'Si se quita la barra de progreso, quitar el comentario de la linea anterior
Set rs = New Recordset
rs.CursorType = adOpenStatic
rs.Open Consulta_SQL, cn

'Iniciar una transaccion para que en caso de que haya errores se pueda recuperar el
'ultimo estado correcto de los datos. En caso de que se produzca algun error durante
'la manipulacion de los mismos se va a la rutina ControlDeErrores, donde se deshacen los
'cambios que se hayan podido producir.
cn.BeginTrans
On Error GoTo ControlDeErrores

ProgressBar1.Min = 0
If (rs.RecordCount > 0) Then
ProgressBar1.Max = rs.RecordCount
Else
ProgressBar1.Max = 1
End If
ProgressBar1.Value = 0
Frame1.Visible = True
Frame1.Refresh
'------FIN BARRA DE PROGRESO

Dim numeroregistros As Long
Set rs_2 = New Recordset
rs_2.CursorType = adOpenStatic

'sql = "select * from Lista_Procesados_Campanya where Id_Campanya = '" & Campanya & "'"
sql = "select * from Lista_Procesados_Campanya_PRUEBAS where Id_Campanya = '" & Campanya & "' and Id_Consulta = '" & Ident_Consulta & "'"

rs_2.Open sql, cn
numeroregistros = rs_2.RecordCount

cont = 0
Do While Not rs.EOF
ident_pers = rs("Id_Persona")
If (persona_disponible(ident_pers)) Then
If numeroregistros <> 0 Then
rs_2.MoveFirst
End If
encontrado = False
Do While Not rs_2.EOF And Not encontrado
If rs_2("Id_Persona") = rs("Id_Persona") Then
encontrado = True
habilitado = rs_2("Habilitado")
End If
rs_2.MoveNext
Loop
If Not encontrado Then
'cmd.CommandText = "insert into Lista_Procesados_Campanya (Id_Campanya, Id_Persona, Habilitado, Usuario) values ('" & Campanya & "', '" & rs("Id_Persona") & "', '1', '" & Usuario & "')"
cmd.CommandText = "insert into Lista_Procesados_Campanya_PRUEBAS (Id_Campanya, Id_Persona, Id_Consulta, Habilitado, Usuario) values ('" & Campanya & "', '" & rs("Id_Persona") & "', '" & Ident_Consulta & "', '1', '" & Usuario & "')"
cmd.Execute
cont = cont + 1
Else
If Not habilitado Then
'cmd.CommandText = "update Lista_Procesados_Campanya set Habilitado = '1' where Id_Campanya = '" & Campanya & "' and Id_Persona = '" & rs("Id_Persona") & "'"
cmd.CommandText = "update Lista_Procesados_Campanya_PRUEBAS set Habilitado = '1' where Id_Campanya = '" & Campanya & "' and Id_Persona = '" & rs("Id_Persona") & "' and Id_Consulta = '" & Ident_Consulta & "'"
cmd.Execute
cont = cont + 1
End If
End If
End If
rs.MoveNext
'------INICIO BARRA DE PROGRESO
If (ProgressBar1.Value < ProgressBar1.Max - 1) Then
ProgressBar1.Value = ProgressBar1.Value + 1
End If
'------FIN BARRA DE PROGRESO
Loop

If cont <> 0 Then
cmd.CommandText = "select * from Consultas_campanya where Id_Campanya = '" & Campanya & "' and Id_Consulta = '" & Ident_Consulta & "'"
Set rs = cmd.Execute
If rs.EOF Then
cmd.CommandText = "insert into Consultas_Campanya (Id_Consulta, Id_Campanya, Habilitado, Usuario) values ('" & Ident_Consulta & "', '" & Campanya & "', '1', '" & Usuario & "')"
Else
If Not rs("Habilitado") Then
cmd.CommandText = "update Consultas_Campanya set Habilitado = '1' where Id_Campanya = '" & Campanya & "' and Id_Consulta = '" & Ident_Consulta & "'"
End If
End If
cmd.Execute
End If

'Si no ha habido ningun problema con los datos grabar los cambios en la base de datos
cn.CommitTrans

If rs.State = adStateOpen Then rs.Close
Set rs = Nothing

If rs_2.State = adStateOpen Then rs_2.Close
Set rs_2 = Nothing
Set cmd = Nothing

'------INICIO BARRA DE PROGRESO
Frame1.Visible = False
'------FIN BARRA DE PROGRESO

ejecutar_consulta = cont
'End Function
Exit Function 'Suprimir esta linea si se quita el control de errores y quitar el comentario de la anterior

ControlDeErrores:
'En caso de que haya habido cualquier problema durante la manipulacion de los datos se
'deshace la transaccion y se deja la base de datos como estaba.
'Se devuelve el valor -2 para que se pueda mostrar un mensaje avisando de que la consulta
'no se ejecuto.
cn.RollbackTrans
Frame1.Visible = False
ejecutar_consulta = -2
End Function|||SEE the Command

SET NOEXEC ON { ON | OFF }

AS in

SET NOEXEC ON

SELECT * FROM table

SET NOEXEC OFF

This might do what you want in VB not sure works in QA I think.

Edit: Not as good a QA check Syntax because it does not valid objects

Tim S|||Thank you very much pica.. for ur ellobrate explanatio...and all for sparing ur time to explain.

with regards
Sudar