#DEFINE CRLF Chr(13)+Chr(10)
User Function Exemplo()
Local cEstrutura := "", cStatement := ""
If !(TCIsConnected())
Return MsgAlert("Você precisa abrir uma conexão com o banco de dados")
EndIf
If !("MSSQL"$TCGetDB())
Return MsgStop(TCGetDB() + " - Nao tratado!")
Endif
cEstrutura := "MyTempTable"
cStatement := "if exists(select name from sysobjects where name like '" + cEstrutura + "%' and xtype = 'U')" + CRLF
cStatement += "begin" + CRLF
cStatement += " drop table " + cEstrutura + "" + CRLF
cStatement += "end" + CRLF
If (TCSQLExec(cStatement) < 0)
Return MsgStop("TCSQLError() " + TCSQLError())
EndIf
cStatement := "create table " + cEstrutura + " (" + CRLF
cStatement += " campo_caractere varchar(20) not null default ' ', " + CRLF
cStatement += " campo_numerico float default 0, " + CRLF
cStatement += " campo_logico varchar(1) not null default 'F', " + CRLF
cStatement += " campo_data varchar(8) not null default ' ' " + CRLF
cStatement += ")"
If (TCSQLExec(cStatement) < 0)
Return MsgStop("TCSQLError() " + TCSQLError())
EndIf
cStatement := "insert into " + cEstrutura + " values ('1st ', 1, 'T', '20080101')"
If (TCSQLExec(cStatement) < 0)
Return MsgStop("TCSQLError() " + TCSQLError())
EndIf
cStatement := "insert into " + cEstrutura + " values ('3nd ', 2, 'F', '20080103')"
If (TCSQLExec(cStatement) < 0)
Return MsgStop("TCSQLError() " + TCSQLError())
EndIf
cStatement := "insert into " + cEstrutura + " values ('3rd ', 3, 'T', '20080103')"
If (TCSQLExec(cStatement) < 0)
Return MsgStop("TCSQLError() " + TCSQLError())
EndIf
cStatement := "insert into " + cEstrutura + " values ('4th ', 4, 'F', '20080104')"
If (TCSQLExec(cStatement) < 0)
Return MsgStop("TCSQLError() " + TCSQLError())
EndIf
cStatement := "update " + cEstrutura + " " + CRLF
cStatement += " set campo_caractere = '2nd ', campo_data = '20080102'" + CRLF
cStatement += "where campo_caractere = '3nd ' and campo_data = '20080103'"
If (TCSQLExec(cStatement) < 0)
Return MsgStop("TCSQLError() " + TCSQLError())
EndIf
cStatement := "delete " + cEstrutura + " where campo_caractere = '4th '"
If (TCSQLExec(cStatement) < 0)
Return MsgStop("TCSQLError() " + TCSQLError())
EndIf
Return