HOW TO WRITE A LOGIC IN SQL SERVER USING THIS COBAL CODE

May 25, 2008

sub = 1

DETAILED-VOUCHER

VOUCHER-A OCCURS 13 TIMES.
ACC-NUM PIC X(6).

ADB-V OCCURS 12 TIMES.
CNT-V PIC 9999 COMP-3.
AMT-V PIC S9(9)V99 COMP-3.

It is a initialization of the two dimensional array DETAILED-VOUCHER(Temporary Variable) which consists of the account number for that account number different group of people say as (teachers, state police etc) have different 12 kinds of amounts such as (DEATH-AMT, PAYEE-AMTetc ) for every account number. SUB (Temporary Variable) is used as subscript whose value will be incremented by 1 after initializing current position by zero in order to initialize all 12 positions in array.



LOP-ZERO-2.
MOVE ZEROS TO CNT-V (1 SUB).
MOVE ZEROS TO AMT-V (1 SUB).
ADD 1 TO SUB.
IF SUB NOT GREATER THAN 12
GO TO LOP-ZERO-2.


MOVE 2 TO SUB.

LOP-ZERO-3.
MOVE CNTS (1) TO CNTS (sub).
ADD 1 TO SUB.
IF SUB NOT > 13 GO TO LOP-ZERO-3.



MOVE '401.21' TO ACC-NO-V (1). ---------- This are the hotcode values
MOVE '410.01' TO ACC-NO-V (2).
MOVE '410.02' TO ACC-NO-V (3).
MOVE '410.03' TO ACC-NO-V (4).
MOVE '410.04' TO ACC-NO-V (5).
MOVE '410.06' TO ACC-NO-V (6).
MOVE '410.05' TO ACC-NO-V (7).
MOVE '411.01' TO ACC-NO-V (8).
MOVE '411.02' TO ACC-NO-V (9).
MOVE '331.01' TO ACC-NO-V (10).
MOVE '212.19' TO ACC-NO-V (11).
MOVE '212.22' TO ACC-NO-V (12).


MOVE ZEROS TO XYZ-S (1).
MOVE ZEROS TO MNO-B (1).
MOVE ALL '9' TO A-KEY
MOVE 01 TO D-X.
MOVE 1 TO SYS-Y



Please give suggest me how to write logic in the sql server. I want to how to write two dimensional array loop in the sql server.

View 1 Replies


ADVERTISEMENT

SQL Server 2008 :: Write Query For Date Logic?

May 25, 2015

I have a below query which have a date filter like "EST_PICK_DATE between '2015-02-01' and '2015-06-01'", where the logic is EST_PICK_DATE should be 3 months from the current month and 1st date of next month. Ex for current month MAY, EST_PICK_DATE shoulc be between '2015-02-01' and '2015-06-01'. I need to write below query dynamically. In below query i have hardcoded the value ("EST_PICK_DATE between '2015-02-01' and '2015-06-01'"), but it should take dynamically. How to achieve this?

I am using this query in SSIS package, So Shall i do in SQL level or we should implement this logic in package? If yes, How?

INSERT INTO STG_Open_Orders (Div_Code, net_price, gross_price) SELECT ord.DIV_CODE AS Div_Code, ord_l.NET_PRICE AS net_price, ord_l.gross_price AS gross_price, FROM ORD ord inner join ORD_L ord_l ONord.ORD_ID=ord_l.ORD_ID WHERE ord_l.EST_PICK_DATE BETWEEN '2015-02-01' AND'2015-06-01'

View 1 Replies View Related

How To Write A Logic ( Give To Same Suggation )

May 20, 2008

View 1 Replies View Related

How To Write Backup Code For Sql Server 2000

Aug 29, 2006

hi Experts,

any one tell me that how to write code to take back up of sql server database?

View 5 Replies View Related

Advanced DateDiff Logic/Code Needed

Jan 5, 2007

I am trying to figure out how much coverage (supervision time) an employee has based on their managers schedule.

Example
Name: Employee, SundayStart: 9 AM, SundayEnd: 5 PM
Name: Manager, SundayStart: 8 AM, SundayEnd: 4 PM


############# 8 AM |Covered Time| 5 PM
Employee ##########|------------|-----
Manger ######------|------------|


Employee is covered for 6 hours on sunday.

Anyway to figure this out? This is what I have so far. Sorry, but im in access 03.


SELECT tblCAESchedule.Name, tblCAESchedule.Title, tblCAESchedule.SunStart, tblCAESchedule.SunEnd,
IIf(DateDiff("n",[tblCAESchedule].[sunstart],[tblCAESchedule].[sunend])>=1,DateDiff("n",[tblCAESchedule].[sunstart],[tblCAESchedule].[sunend]),DateDiff("n",[tblCAESchedule].[sunstart],[tblCAESchedule].[sunend])+1440)/60 AS SunHours,
tblSupSchedule.Name, tblSupSchedule.SunStart, tblSupSchedule.SunEnd,
Abs(DateDiff("n",[tblCAESchedule].[sunstart],[tblSupSchedule].[sunstart])/60) AS StartDif,
Abs(DateDiff("n",[tblCAESchedule].[sunend],[tblSupSchedule].[sunend])/60) AS EndDif,
Abs(DateDiff("n",[tblCAESchedule].[sunstart],[tblSupSchedule].[sunstart])/60)+Abs(DateDiff("n",[tblCAESchedule].[sunend],[tblSupSchedule].[sunend])/60) AS ShiftDif
FROM tblCAESchedule INNER JOIN tblSupSchedule ON tblCAESchedule.Skill = tblSupSchedule.Skill
WHERE tblCAESchedule.Skill = "Sales"

View 4 Replies View Related

How Do I Write It In The Code?

May 20, 2005

Hejsan!
I have a page with with diffrent short news. They are in a Database
(MS SQL) and now they saving all after the other, but I should want to
only have 3 news in the DB, and when I write in a new short news it
should be saved over one of them older new witch is in the databaseHow
can I do that? Anyone who nows to write that in the code?mvh Sanne
My code looks like this now:<script runat="server">
    Sub Page_Load(sender As Object, e As EventArgs)       Dim myConnection As SqlConnection       Dim myCommand As SqlDataAdapter       ' Create a connection to the "pubs" SQL database located on the       ' local computer.         
myConnection = New
SqlConnection("server=xxxxx;UID=xxxx;PWD=xxxx;Initial Catalog=xxx;")       ' Connect to the SQL database using a SQL SELECT query to get all       ' the data from the "notistabell" table.       myCommand = New SqlDataAdapter("SELECT * FROM notiser ORDER BY ID Desc", myConnection)       ' Create and fill a DataSet.       Dim ds As DataSet = new DataSet()       myCommand.Fill(ds)       ' Bind MyDataList to the DataSet. MyDataList is the ID for       ' the DataList control in the HTML section of the page.       MyDataList.DataSource = ds       MyDataList.DataBind()    End Sub
</script>

View 1 Replies View Related

HOW TO WRITE THIS CODE?

Apr 4, 2008

OKAY I have one table "Data" with about 7 million records.
Now I want to create the following output table. THe range (1 to 15) can always change in the "data" table. How would I write a script to do this?

Data
StartEndTime
1155:45
20262:26
1521607:52



Output
ValueTime
15:45
25:45
35:45
45:45
55:45
65:45
75:45
85:45
95:45
105:45
115:45
125:45
135:45
145:45
155:45
202:26
212:26
222:26
232:26
242:26
252:26
262:26
1527:52
1537:52
1547:52
1557:52
1567:52
1577:52
1587:52
1597:52
1607:52

View 9 Replies View Related

How Can We Write C# Code In Sql.

Feb 19, 2006

Hello

Anybody knows how to write c# in SQL?

All responses appreciated.

thanks.





View 6 Replies View Related

How To Write The Code For Connection In C#.net

Jan 4, 2008

 what is the simple way of writing code for the connection  with sql server  in c# .net
could any one provideme with the code for the same ism not been able to understand the funda  of using class for the connection purpose
if any one knows plz let me know i am waiting

View 3 Replies View Related

How To Write Code Without Cursor

Aug 25, 2014

I wrote the foollowing cursor code but it takes too long.how i can write it without cursor?

ALTER PROCEDURE [dbo].[usp_AMPPU_Teamleader]
AS
BEGIN
SET NOCOUNT ON;

[code]....

View 8 Replies View Related

Where Can I Write Vb.net Code To Run Rs.exe Utility

May 16, 2008



Hi,
I want to write a script in Vb.net and use that script in rs.exe utility..but i am not able to understand where should i have to write the script in Vb.net for reporting services.
Why i am writing the script code is???

In Report manger,i am trying to restrict folders and reports for particular persons only like manger can see all the reports,advisor can view only related reports.
this can do by using item level security in report manger by creating roles and we can add the users in to the role.
but that was not happenning..planning for another way to implement the scenario.

I came to know that we can write scripting in vb.net and we can run thru rs.exe utility in SSRS.

1.But where can i write the vb.net script?
2.How to migrate that code to report manager?
3.Can we debug that code?
4.How to use SOAP API in RS?

Pls reply back..this one i have to do with in one day..


View 1 Replies View Related

Trying To Work Out Why My Code Wont Update Or Write To The DB

Jan 7, 2008

hi there, i have been wrestling with this for quite a while, as in my other post http://forums.asp.net/t/1194975.aspx, what someone advised me was to put in try catch blocks ot see whats going on, problem is i have never really done it whit this kinda thing before, and i was wondering if someone could point me in the right direction.
 
For example where would i put the try catch block in here, to show me if its not working public int getLocationID(int ProductID, int StockLoc)
{
// Gets the LocationID (Shelf ID?) for the stock column and product id
// passed
// The SQL will look Something like: string strSQL;
strSQL = "SELECT " + " location" + StockLoc + " " + "FROM " + " tbl_stock_part_multi_location " + "WHERE " + " stock_id = " + ProductID;string sConnectionString = "Data Source=xxxxx;Initial Catalog=xxxx;User ID=xxxx;Password=xxxxx";
SqlConnection objConnGetLocationID = new SqlConnection(sConnectionString);SqlCommand sqlCmdGetLocationID = new SqlCommand(strSQL, objConnGetLocationID);
objConnGetLocationID.Open();int intLocation = Convert.ToInt32(sqlCmdGetLocationID.ExecuteScalar());
return intLocation;
}

View 6 Replies View Related

How To Write Portable Database Access Code?

Jul 20, 2005

I can access Microsoft Access database via ODBC on Windows 2000 usingC++. Now, I would like to use the SAME piece of code to access MS SQLon Windows. Can I achieve this without any modification to my existingcodes?Then, I would like to use the SAME piece of codes to access Oracleon Windows? Is it possible?Thanks in advance!

View 1 Replies View Related

Ugrent Help: How To Write Code To Execute A Batch File

Apr 15, 1999

hi, I need to run a batch file in specific time of the week. can anyone show me the code to run a batch file with both ways: window nt schedualer and ms sql server task manger.... I do appreciate your help

Ali

View 5 Replies View Related

Can I Write A Dll(or Share The Same Code) That Works On Both Mobile Device And Pc?

May 4, 2007

hi,

Can I write a dll(or share the same code) that works on both Mobile device and pc? Since we are using compact edition, we are hoping we can write some common module with the same code that could works on both mobile device and pc platform. I noticed the reference is the same, System.Data.SqlServerCe.dll 3.0.

Another question is, we already have a module for SQLCE2.0, with .net CF1.0. Now, we will start to use compact edition, should we just update on the 1.0 one, or we have to write a different one based on .net CF2.0? Can I use compact edition in CF1.0 dll?



Thanks.

View 1 Replies View Related

Write Code To Combine Two Tables And Then Return Maximum Value Of One Table

Sep 17, 2012

I am TRYING to write code to combine two tables and then return the maximum value of one table, but SQL Server keeps telling me that the column is not valid.... I have added attached screenshots to show that it IS a valid column, so I cannot figure out what is the retarded issue!!

View 11 Replies View Related

How To Create Apps That Write Code To Retrieve Data With Foreign Keys?

Apr 6, 2007

Hi GuysOff late, I've grown with programming that requires more than a number of tables that has foreign keys with other tables' primary keys. It takes a really cumbersome coding to retrieve the code from another table with the other table having foreign keys. My question is, how do we program VS 2005 such that it does all the retrieval of the data from the database instead of us writing the code all by ourself?Is it really good database technique to bend the normalcy rules and have one to two columns having redundant data?Can anyone tell me how to write code that retrieves the foreign key data when the data from the other table is called?Thanks

View 2 Replies View Related

Integration Services :: How To Write ETL Package Addressing Different Collations Or Code Pages

Jul 13, 2015

Default code page in ETL package is 1252 which will not work if the collation is different e.g in Japanese_CI_AS, it is 932.

My question is how to write a generic ETL package so that it can cater any collation or any code page.

View 5 Replies View Related

SQL 2000 Reovery Fails Sometimes. Error Code (Error 3136). How To Make Database Write Mode?

Jan 7, 2008

Hello,

I am applying hourly differential backup to the backup server from production with the following command. This command makes the database on standby server into read only mode.


RESTORE DATABASE ARSYSTEM FROM DISK = 'E:SQL backup from productionsql_full_backup'
WITH MOVE 'arsystem' TO
'd:ardataarsystem.mdf' ,
MOVE 'arsystem_log' TO 'D:ARLOGARsystem' ,
STANDBY = 'E:SQL backup from productionSQL daily diff back up'


Now I want to run a command which will put the database in write mode. I have created a job which would make the datbase Write mode. This job runs successfully sometimes and fails sometimes. I need to ensure that the job always succeeds. When it fails, how do I troubleshoot and what is the possible fix?

Thanks in advance.

The error message is

Cannot apply the backup on device 'E:SQL backup from productionSQL daily diff back up' to database 'ARSYSTEM'. [SQLSTATE 42000] (Error 3136) RESTORE DATABASE is terminating abnormally. [SQLSTATE 42000] (Error 3013). The step failed.


The steps for the job are as follows with the failing step highlighted in bold.


copy /y "\172.31.9.12Remedy BackupackupSQL backupsql_full_backup" "E:SQL backup from productionsql_full_backup"

copy /y "\172.31.9.12Remedy BackupackupSQL backupSQL daily diff back up" "E:SQL backup from productionSQL daily diff back up"

xp_cmdshell 'net stop "bmc remedy action request system server"'

exec rp_kill_db_processes 'ARSYSTEM'

RESTORE DATABASE ARSYSTEM

FROM DISK = 'E:SQL backup from productionsql_full_backup'

WITH

MOVE 'arsystem' TO 'd:ardataarsystem.mdf' ,

MOVE 'arsystem_log' TO 'D:ARLOGARsystem' ,

NORECOVERY


Failing step

RESTORE DATABASE ARSYSTEM

FROM DISK = 'E:SQL backup from productionSQL daily diff back up'

WITH

MOVE 'arsystem' TO 'd:ardataarsystem.mdf' ,

MOVE 'arsystem_log' TO 'D:ARLOGARsystem' ,

RECOVERY



xp_cmdshell 'del /f "E:SQL backup from productionsql_full_backup"'

xp_cmdshell 'del /f "E:SQL backup from productionsql daily diff back up"'

xp_cmdshell 'net start "bmc remedy action request system server"'





I have scheduled the following hourly diffential restore job too which never fails.

RESTORE DATABASE ARSYSTEM FROM DISK = 'E:SQL backup from productionsql_full_backup'
WITH MOVE 'arsystem' TO
'd:ardataarsystem.mdf' ,
MOVE 'arsystem_log' TO 'D:ARLOGARsystem' ,
STANDBY = 'E:SQL backup from productionSQL daily diff back up'
EXEC MASTER..XP_CMDSHELL 'del /f "E:SQL backup from productionSQL daily diff back up"'

View 12 Replies View Related

Help With Converting Code: VB Code In SQL Server 2000-&&>Visual Studio BI 2005

Jul 27, 2006

Hi all--I'm trying to convert a function which I inherited from a SQL Server 2000 DTS package to something usable in an SSIS package in SQL Server 2005. Given the original code here:
Function Main()
on error resume next
dim cn, i, rs, sSQL
Set cn = CreateObject("ADODB.Connection")
cn.Open "Provider=sqloledb;Server=<server_name>;Database=<db_name>;User ID=<sysadmin_user>;Password=<password>"
set rs = CreateObject("ADODB.Recordset")
set rs = DTSGlobalVariables("SQLstring").value

for i = 1 to rs.RecordCount
sSQL = rs.Fields(0).value
cn.Execute sSQL, , 128 'adExecuteNoRecords option for faster execution
rs.MoveNext
Next

Main = DTSTaskExecResult_Success

End Function

This code was originally programmed in the SQL Server ActiveX Task type in a DTS package designed to take an open-ended number of SQL statements generated by another task as input, then execute each SQL statement sequentially. Upon this code's success, move on to the next step. (Of course, there was no additional documentation with this code. :-)

Based on other postings, I attempted to push this code into a Visual Studio BI 2005 Script Task with the following change:

public Sub Main()

...

Dts.TaskResult = Dts.Results.Success

End Class

I get the following error when I attempt to compile this:

Error 30209: Option Strict On requires all variable declarations to have an 'As' clause.

I am new to Visual Basic, so I'm on a learning curve here. From what I know of this script:
- The variables here violate the new Option Strict On requirement in VS 2005 to declare what type of object your variable is supposed to use.

- I need to explicitly declare each object, unless I turn off the Option Strict On (which didn't seem recommended, based on what I read).

Given this statement:

dim cn, i, rs, sSQL

I'm looking at "i" as type Integer; rs and sSQL are open-ended arrays, but can't quite figure out how to read the code here:

Set cn = CreateObject("ADODB.Connection")

cn.Open "Provider=sqloledb;Server=<server_name>;Database=<db_name>;User ID=<sysadmin_user>;Password=<password>"

set rs = CreateObject("ADODB.Recordset")

This code seems to create an instance of a COM component, then pass provider information and create the recordset being passed in by the previous task, but am not sure whether this syntax is correct for VS 2005 or what data type declaration to make here. Any ideas/help on how to rewrite this code would be greatly appreciated!

View 7 Replies View Related

Server Reconnection Logic

Mar 30, 2004

Hi,

I am a bit of a novice to SQL Server programming. So, forgive me if my question is too silly or easy.

I have an client-server application where the server connects to an SQL Server and does simple DB operations. In a particular test case, after my SQL Server is shut down and restarted when I try to execute an SQL Statement, the SQLExecute function fails. The problem is that the connection handle used to allocate and prepare the statement is invalid. So, I need to reconnect to the server.

Now my question is, how do I determine if the connection handle is valid or not ? That is, is there any API/function which when used can detect whether the connection handle is invalid or not.

I have tried calls to SQLGetConnectAttr and SQLGetInfo passing the connection handle, but these API's still return the correct value even if the handle is invalid.

Thanks in advance,

Ganesh

View 3 Replies View Related

SQL Server Query Logic

Apr 14, 2008

Hi, sorry for another newbie question but I was wondering if the following is possible:

I have to take some information from a table which I have already created a query for. This information then has to be inserted into a new table but needs another column (not the promary key) with another unique custom identifer for each record in the format EX01 which is incremented by 1 for each record. I was wondering how is it possible to do this?

My approach was to create a view and then insert the values form the view into the new table but I still have no idea how to do the unique identifer. Was the first part of my approach correct or have been wrong from the start?

Thanks for any help.

View 1 Replies View Related

Moving A Logic Loop To SQL Server

Jan 14, 2006

I am using C# and ASP.NET 2.0, with SQL Server 2000. In my database I have a table that is similar to the following:
    WebpageId     WebpageAddress    Handler        1         /company/about    ~/about.aspx        2         /blog             ~/blog.aspx
As you can guess, one of my queries will be a SELECT command where WebpageAddress = @address.
The hiccup I have is with a friendly URL such as the following:
    /blog/2005/10/6
The friendly URLs have no extension, so I cannot immediately "pick out" the extension. (If the address were /blog.aspx/2005/10/6, then things would be simpler.)
What I am doing at present is using a loop in C# where I first perform a query with that full address. If no match is found, I trim the address back to the last slash (/blog/2005/10) and perform another query. If no match is found, I trim the address (/blog/2005) and perform another query. Again, no match is found, so I trim the address again (/blog) and perform yet another query. This time, a match is found, in which case the URL rewriting looks vaguely like this:
    ~/blog.aspx?parameters=2005/10/6
While this works fine, these friendly URLs require hitting the database up to four or five times. My question is, can this looping logic be moved to SQL Server?
My SQL knowledge is extremely basic, so I am just looking for someone to point me in the right direction. If it is not possible, I'd love to know now rather than wasting hours trying. If it is possible, I've love to know the keyword or technique involved, so that I can Google for the full answer.

View 1 Replies View Related

SQL Server 2008 :: Concatenate Rows With For XML Logic

Feb 24, 2015

I am not able to understand why just appending blank string in below code removes '<item>' from xml result.Is it converting to varchar datatype ?

This question is just for my understanding

CREATE TABLE #tbl
(id INT IDENTITY(1,1),
item varchar(100))

INSERT #tbl
SELECT 'This'
UNION ALL

[Code] .....

View 4 Replies View Related

SQL Server 2012 :: Create A Function That Take A Value And Run Some Logic And Output The Value?

Feb 20, 2015

I would like to create a function that take a value and run some logic and output the value

I have a table like this

Table A
value
*
001
004.00
3.0
1.22

Logic I want to run is

The value that you are passing is numeric and numeric with only decimal 0 value, and then convert it to integer otherwise leave as it is

So if I run a query something like this

Select value, fn_convertointerger(value) as converted_value from TableA

I will get

Value converted_value
* *
001 1
004.00 4
3.0 3
1.22 1.22
2.02 2.02
4.000 4
Jkil& Jkil&

How can I create a function like this to convert specific numeric value?

View 9 Replies View Related

SQL Server 2008 :: Logic To Split Monthly Numbers

Sep 22, 2015

I am trying to split the annual cost into monthly numbers based on the contract Period.Since the contract period varies from company to company not sure how to implement the logic.

create table #Invoice
(
Company Varchar(50),
Startdate2015 DateTime,
EndDate2015 DateTime,
ContractPeriod2015 Int,
ContractAmount2015 Float,

[code]..

View 3 Replies View Related

How To Implement The For Loop Logic In Sql Server Reporting Services

Dec 17, 2007

Hi All,

This is the code for calculating a formula field in Crystal Reports.
I want to implement the same in Sql Server Reporting Services..
But it doesn't have the feature of For Loop....
The strings started with @ are formula fields....
Can anyone tell me, how can the below code be implemented in Sql Server Reporting Services

numbervar YR;
for YR := 1 to {@CalcFiscalAge} step 1 do
(
IF YR = {@CalcLifeCode} +1 then
locFactor1 := 1;
exit for;
IF (YR = 1 OR YR = {@CalcFiscalAge}) THEN
HALF_YEAR := 2
ELSE
HALF_YEAR := 1 ;
LINEAR := ROUND(REM/ ({@CalcLifeCode}-YR+1.5)/HALF_YEAR,4);
MACR := ROUND(REM / {@CalcLifeCode}*{@CalcSRate}/HALF_YEAR,4);
IF MACR >= LINEAR then
DEP := MACR
ELSE
DEP := LINEAR;
locFactor1 := locFactor1 + DEP ;
REM := 1 - locFactor1;
locFactor := locFactor1;
);



Thanks in advance

Regards,

View 3 Replies View Related

How To Write .net Code To Place XML Messages On Queues And Retrieve XML Messages From Queues.

Apr 2, 2008

Hello, please help!!

I have spent days searching the web and forums for an answer to this simple question and cannot find an example.

I have built a service broker application on sql server 2005. The application puts some xml on an incoming queue which is basically a few parameters to be used in a query. This queue will then call a stored proc which does some business logic and puts the resulting results in another queue also in xml.

I have written a test harness in SQL to put messages on the inbound queue and then some sql to retrieve the returned code from the outbound queue.

What I want to do is be able to convert the SQL which does this into .net code to be used by an application. i.e. write in .net some code to put xml on a queue and then write some .net code to retrieve xml from another queue.

I wouldn't have thought this would be a difficult thing to do and would have been done hundreds of times, but unable to find anything to simply send and retrieve XML to service broker queues....

thanks for your help.. its really needed. I found some links, but they are really vague and often doing select statments in service broker or something like this. I don't want to call any sql, just send and recieve XML on the queues.

any example code that does this, would be really helpfull

kind regards,
David Weeden
Database Developer

View 2 Replies View Related

SQL Server 2012 :: Stored Procedure With Conditional IF Statement Logic

Aug 9, 2015

I have a data model with 7 tables and I'm trying to write a stored procedure for each table that allows four actions. Each stored procedure should have 4 parameters to allow a user to insert, select, update and delete a record from the table.

I want to have a stored procedure that can accept those 4 parameters so I only need to have one stored procedure per table instead of having 28 stored procedures for those 4 actions for 7 tables. I haven't found a good example online yet of conditional logic used in a stored procedure.

Is there a way to add a conditional logic IF statement to a stored procedure so if the parameter was INSERT, go run this statement, if it was UPDATE, go run this statement, etc?

I have attached my data model for reference.

View 9 Replies View Related

Issues About Deploy Business Logic Handler To A Web Server For Web Replication.

Jul 23, 2007

Pocket PC 2003, SQL Compact Edition, SQL2005, IIS6.0



I implemented a business logic handler to deal with conflicts. When I deploy it on the SQL server which is also the web replication server, the logic handler seems working fine. However, if I deploy this handler to another web server. The logic handler failed to be loaded.

My enviroment settings are desribed as below.



Machine A, distributor, with database and publication. The business logic handler is deployed at C:Program FilesMicrosoft SQL Server90COMBusinessLogicHandler.dll. It's registered by using sp_registercustomresolver. The @assembly is specified as @assembly=C:Program FilesMicrosoft SQL Server90COMBusinessLogicHandler.dll';



Machine B, IIS server. The same business logic handler is deployed at C:Program FilesMicrosoft SQL Server90COMBusinessLogicHandler.dll on the Machine B itself.



When I ran the web replication, the Merge Agent reported the error as below.

Error loading custom assembly "C:Program FilesMicrosoft SQL Server90COMBusinessLogicHandler.dll", Error: "Could not load file or assembly 'C:\Program Files\Microsoft SQL Server\90\COM\BusinessLogicHandler.dll' or one of its dependencies. The given assembly name or codebase was invalid.



It seemed that the Merge Agent had trouble to find my logic handler because the path reported in the error log has two backward slashes. I have no idea where did that came from. I am not sure if that's the cause of the error. Without business logic handler. I had successfully finished web replication of Machine B to sync with Machine A. If I setup web replication directly on Machine A with business logic handler, I can successfully sync as well.



Does anyone has any idea about how to correctly deploy business logic handler on a web server?



Thanks,

Nigel

View 1 Replies View Related

SQL Server 2012 :: Error Creating Temp Table Based On IF Logic

Nov 13, 2014

I could deploy across my environment, which is a mix of 2008R2/2012 servers, to give some information on log files. Running into a silly issue right off the bat. The table that DBCC LogInfo() conjures out of magic is different between the two. In 2012 it gained the RecoveryUnitID column. So I'm trying to write some logic to create a temp table based on which version is running. I would like to avoid a global temp table if possible. Here's what I've tried:

sp_executesql creates a table outside of the scope of my session:
DECLARE @PrVers NVARCHAR(128)
, @PrVersNum DECIMAL(10,2)
, @StageTable NVARCHAR(1024) = N''

[code]....

View 9 Replies View Related

SQL Server 2012 :: Conditional Logic Function To Return VARCHAR Value With Gender

May 4, 2015

I'm trying to convert the query immediately below into a function with the conditional logic to return a VARCHAR value with the gender: male, female or unknown.

SELECT empid, firstname, lastname, titleofcourtesy,
CASE
WHEN titleofcourtesy IN('Ms.', 'Mrs.') THEN 'Female'
WHEN titleofcourtesy = 'Mr.' THEN 'Male'
ELSE 'Unknown'
END AS gender
FROM HR.Employees;
GO

Below is the conditional logic function I'm trying to create to replicate the logic above.

CREATE FUNCTION dbo.Gender
(
@male AS VARCHAR(10),
@female AS VARCHAR(10),
@unknown AS VARCHAR(10)
)
RETURNS VARCHAR(10)

[Code] .....

View 6 Replies View Related

SQL Server 2012 :: Replacing CASE Statement In Update With Table-driven Logic

Oct 20, 2014

I have a stored proc that contains an update which utilizes a case statement to populate values in a particular column in a table, based on values found in other columns within the same table. The existing update looks like this (object names and values have been changed to protect the innocent):

UPDATE dbo.target_table
set target_column =
case
when source_column_1= 'ABC'then 'XYZ'
when source_column_2= '123'then 'PDQ'

[Code] ....

The powers that be would like to replace this case statement with some sort of table-driven structure, so that the mapping rules defined above can be maintained in the database by the business owner, rather than having it embedded in code and thus requiring developer intervention to perform changes/additions to the rules.

The rules defined in the case statement are in a pre-defined sequence which reflects the order of precedence in which the rules are to be applied (in other words, if a matching value in source_column_1 is found, this trumps a conflicting matching value in source_column_2, etc). A case statement handles this nicely, of course, because the case statement will stop when it finds the first "hit" amongst the WHEN clauses, testing each in the order in which they are coded in the proc logic.

What I'm struggling with is how to replicate this using a lookup table of some sort and joins from the target table to the lookup to replace the above case statement. I'm thinking that I would need a lookup table that has column name/value pairings, with a sequence number on each row that designates the row's placement in the precedence hierarchy. I'd then join to the lookup table somehow based on column names and values and return the match with the lowest sequence number, or something to that effect.

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved