I need to input into a table a list of 126 Sites with 7 types of pitches. The script I have written is not right and I cannot figure out why.
What I would like to see is a column of Site_Skey 1, 1, 1, 1, 1, 1, 1 and a column of PitchType_Skey 1,2,3,4,5,6,7 then Site_Skey 2,2,2,2,2,2,2 and a column of PitchType_Skey 1,2,3,4,5,6,7 this need to be repeated 126 times.
Can you help?
Current Script:
DECLARE #PitchType_Skey INT
DECLARE #Site_Skey INT
SET #PitchType_Skey = 1
SET #Site_Skey = 1
WHILE (#PitchType_Skey <= 882)
WHILE (#Site_Skey <= 882)
BEGIN
INSERT INTO Capacity (PitchType_Skey, Site_Skey)
SELECT (CASE WHEN #PitchType_Skey % 7 = 0 THEN 7 ELSE #PitchType_Skey % 7 END),
(CASE WHEN #Site_Skey % 126 = 0 THEN 126 ELSE #Site_Skey % 126 END)
SET #PitchType_Skey = #PitchType_Skey + 1
SET #Site_Skey = #Site_Skey + 1
END
much simpilar way of doing it....
DECLARE #PitchType_Skey INT
DECLARE #Site_Skey INT
SET #PitchType_Skey = 1
SET #Site_Skey = 1
WHILE (#Site_Skey < 127)
BEGIN
IF #PitchType_Skey = 8
BEGIN
SET #PitchType_Skey = 1
SET #Site_Skey = #Site_Skey + 1
END
IF (#Site_Skey < 127)
BEGIN
INSERT INTO dbo.Capacity (PitchType_Skey, Site_Skey)
SELECT #PitchType_Skey, #Site_Skey
END
SET #PitchType_Skey = #PitchType_Skey + 1
END
Related
I seem to be having a lot of difficulty accumulating and then outputting a variable in MATLAB.
Please see the code below. All I want to do is to add the decimal representation to the totalsum. I've tried what feels like a million things. I think I am misunderstanding how to iterate through a MATLAB vector. Seems simple enough.
%clear the command window
clc();
%clear all of the variable stored
clear all;
% close all plots and figures
close();
num = 1.32421875000000000000;
format long g;
%bin_num = dec2bin(num);
fprintf("binary representation of num: %.45f \n", num);
num = num + (1/2^52);
fprintf("the next largest number is: %.45f \n", num);
num = num - (1/2^52);
%bin = '0011111111110101001011111111111111111111111111111111111111111111'
sign = '0';
exponent = '0 1 1 1 1 1 1 1 1 1 1';
decexponent = bin2dec(exponent);
mantissa = [0 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1];
for i = 1:1:length(mantissa)
sumtotal = sumtotal + mantissa(i)*(1/(2^i)));
end
%num = (-1)^bin2dec(sign)*(2^(decexponent-1023))*(1 + sum);
fprintf("the next smallest number is: %.45f \n", (sumtotal));
There were some errors. I removed the errors and it worked.
Output is as follow
binary representation of num: 1.324218750000000000000000000000000000000000000
the next largest number is: 1.324218750000000222044604925031308084726333618
the next smallest number is: 0.324218749999999777955395074968691915273666382
Use the below code and please tell me do you want to do this ..
%clear the command window
clc();
%clear all of the variable stored
clear all;
% close all plots and figures
close();
num = 1.32421875000000000000;
format long g;
%bin_num = dec2bin(num);
fprintf("binary representation of num: %.45f \n", num);
num = num + (1/2^52);
fprintf("the next largest number is: %.45f \n", num);
num = num - (1/2^52);
%bin = '0011111111110101001011111111111111111111111111111111111111111111'
sign = '0';
exponent = '0 1 1 1 1 1 1 1 1 1 1';
decexponent = bin2dec(exponent);
sumtotal=0;
mantissa = [0 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1];
for i = 1:1:length(mantissa)
sumtotal = sumtotal + mantissa(i)*(1/(2^i));
end
%num = (-1)^bin2dec(sign)*(2^(decexponent-1023))*(1 + sum);
fprintf("the next smallest number is: %.45f \n", (sumtotal));
function [w]=example3(v)
w=[0];
for x =v
for y=v
w(x,y)=x+y;
end
end
end
An example:
v=[5 2];
[w]=example3(v)
0 0 0 0 0
0 4 0 0 7
0 0 0 0 0
0 0 0 0 0
0 7 0 0 10
I have this code and I'm trying to figure out how often does the value change for w. More than that though, I want to , step by step, how the value of w change (maybe just the first few iterations of it).
As suggested by others, you can define a break point where you assign a value to w and see its value.
If you want to do it programmatically, you could add this:
function [w]=example3(v)
w=[0];
idx = 0; % Count number of cycles
for x =v
for y=v
w(x,y)=x+y;
idx = idx + 1;
if idx < 6 % Only display first 5 values
disp(['x: ' num2str(x) ' - y: ' ...
num2str(y) ' - w: ' num2str(w(x,y))])
end
end
end
end
Let g be a matrix containing ones\zeroes. I want to fill up gaps of zeros (complete ones sequences) in the rows of g which are smaller then a given k.
For example fill up with ones all gaps smaller then three zeros. This code will work:
[m,n]=size(g);
k=3
for i=1:m
j=1
while (j<n)
if(g(i,j)==0)
flag=0;
for w=1:k
if(g(i,j+w-1)==1)
flag=1;
end
end
if(flag)
for w=1:k
g(i,j+w-1)=1;
end
else
while(~flag&j<n)
j=j+1;
if(g(i,j)==1)
flag=1;
end
end
end
end
j=j+1;
end
end
Is there a way to do so without all the for loops?
A short version using some built-in function:
M = [1 1 1 1 1
1 1 1 0 0
1 1 1 0 1
1 1 0 0 0
0 1 1 1 1]
Mopen = ~imopen(~padarray(M,[0,1],1),strel('line',3,0));
Mfill = Mopen(:,2:end-1);
A vectorized version:
k = 3;
d = diff( g,1,2);
L = d ~= 0;
c = cumsum([zeros(size(g,1),1) L],2)+1;
b = bsxfun(#plus, c, cumsum([0; c(1:end-1,end)]));
a =accumarray(reshape(b.',[],1),1);
f= find(a<k);
g(ismember(b,f) & g==0) = 1;
Example :
g =
1 1 1 1 1
1 1 1 0 0
1 1 1 0 1
1 1 0 0 0
0 1 1 1 1
result =
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 0 0 0
1 1 1 1 1
Another potential solution is to cast each row to a char array and then perform substitutions based on a regular expressions
g = round(rand(30,70));
figure();
subplot(121);
imagesc(g)
[m,n]=size(g);
k=3;
pattern = ['(?<!',char(0),')(',char(0),'{1,',num2str(k-1),'})(?!',char(0),')'];
for i=1:m
[matchstart,matchend] = regexp(char(g(i,:)),pattern);
for j = 1:length(matchstart)
g(i,matchstart(j):matchend(j)) = 1;
end
end
subplot(122);
imagesc(g)
I'm migrating from MySQL to oracle i got the script generated on MySQL and when creating a view MySQL add this:
Begin DesignProperties =
Begin PaneConfigurations =
Begin PaneConfiguration = 0
NumPanes = 4
Configuration = "(H (1[40] 4[20] 2[20] 3) )"
End
Begin PaneConfiguration = 1
NumPanes = 3
Configuration = "(H (1 [50] 4 [25] 3))"
End
Begin PaneConfiguration = 2
NumPanes = 3
Configuration = "(H (1 [50] 2 [25] 3))"
End
Begin PaneConfiguration = 3
NumPanes = 3
Configuration = "(H (4 [30] 2 [40] 3))"
End
Begin PaneConfiguration = 4
NumPanes = 2
Configuration = "(H (1 [56] 3))"
End
Begin PaneConfiguration = 5
NumPanes = 2
Configuration = "(H (2 [66] 3))"
End
Begin PaneConfiguration = 6
NumPanes = 2
Configuration = "(H (4 [50] 3))"
End
Begin PaneConfiguration = 7
NumPanes = 1
Configuration = "(V (3))"
End
Begin PaneConfiguration = 8
NumPanes = 3
Configuration = "(H (1[56] 4[18] 2) )"
End
Begin PaneConfiguration = 9
NumPanes = 2
Configuration = "(H (1 [75] 4))"
End
Begin PaneConfiguration = 10
NumPanes = 2
Configuration = "(H (1[66] 2) )"
End
Begin PaneConfiguration = 11
NumPanes = 2
Configuration = "(H (4 [60] 2))"
End
Begin PaneConfiguration = 12
NumPanes = 1
Configuration = "(H (1) )"
End
Begin PaneConfiguration = 13
NumPanes = 1
Configuration = "(V (4))"
End
Begin PaneConfiguration = 14
NumPanes = 1
Configuration = "(V (2))"
End
ActivePaneConfig = 0
End
Begin DiagramPane =
Begin Origin =
Top = 0
Left = 0
End
Begin Tables =
Begin Table = "TB"
Begin Extent =
Top = 6
Left = 38
Bottom = 114
Right = 189
End
DisplayFlags = 280
TopColumn = 0
End
End
End
Begin SQLPane =
End
Begin DataPane =
Begin ParameterDefaults = ""
End
Begin ColumnWidths = 9
Width = 284
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
End
End
Begin CriteriaPane =
Begin ColumnWidths = 11
Column = 1440
Alias = 900
Table = 1170
Output = 720
Append = 1400
NewValue = 1170
SortType = 1350
SortOrder = 1410
GroupBy = 1350
Filter = 1350
Or = 1350
Or = 1350
Or = 1350
End
End
End
I have created the view with no problem on oracle
but since i´m new on oracle i don't know if this code is necessary or its just necessary on MySQL, if it is necessary how can i get it done on oracle?
This code looks like the extended properties for SQL Server Management Studio (SSMS) which are added to the view so your GUI Design layout will be loaded again if you open that view again in the GUI - but you said you are doing MySQL to Oracle not SQL Server to Oracle so not sure why you are using SSMS.
This isn't required for the view to work (in any database) only to set the layout of the designer view in SSMS so there is no need to add it into your Oracle view.
If you use Tasks -> Generate Scripts to export your VIEW code via SSMS you can disable scripting of extended properties in the Advanced Options by setting Script Extended Properties to false.
I am doing a comparison of my Dev and QA databases. My Dev database has a bunch of sp_addextendedproperty information, which prevents the scripts from being an exact match. I tried dropping and recreating the offending view, but the noise is still there. How can I remove sp_addextendedproperty from a SQL Server 2008 R2 view script?
EXECUTE sp_addextendedproperty #name = N'MS_DiagramPane1', #value = N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties =
Begin PaneConfigurations =
Begin PaneConfiguration = 0
NumPanes = 4
Configuration = "(H (1[40] 4[20] 2[20] 3) )"
End
Begin PaneConfiguration = 1
NumPanes = 3
Configuration = "(H (1 [50] 4 [25] 3))"
End
Begin PaneConfiguration = 2
NumPanes = 3
Configuration = "(H (1 [50] 2 [25] 3))"
End
Begin PaneConfiguration = 3
NumPanes = 3
Configuration = "(H (4 [30] 2 [40] 3))"
End
Begin PaneConfiguration = 4
NumPanes = 2
Configuration = "(H (1 [56] 3))"
End
Begin PaneConfiguration = 5
NumPanes = 2
Configuration = "(H (2 [66] 3))"
End
Begin PaneConfiguration = 6
NumPanes = 2
Configuration = "(H (4 [50] 3))"
End
Begin PaneConfiguration = 7
NumPanes = 1
Configuration = "(V (3))"
End
Begin PaneConfiguration = 8
NumPanes = 3
Configuration = "(H (1[56] 4[18] 2) )"
End
Begin PaneConfiguration = 9
NumPanes = 2
Configuration = "(H (1 [75] 4))"
End
Begin PaneConfiguration = 10
NumPanes = 2
Configuration = "(H (1[66] 2) )"
End
Begin PaneConfiguration = 11
NumPanes = 2
Configuration = "(H (4 [60] 2))"
End
Begin PaneConfiguration = 12
NumPanes = 1
Configuration = "(H (1) )"
End
Begin PaneConfiguration = 13
NumPanes = 1
Configuration = "(V (4))"
End
Begin PaneConfiguration = 14
NumPanes = 1
Configuration = "(V (2))"
End
ActivePaneConfig = 0
End
Begin DiagramPane =
Begin Origin =
Top = 0
Left = 0
End
Begin Tables =
Begin Table = "apc"
Begin Extent =
Top = 6
Left = 38
Bottom = 125
Right = 236
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "p"
Begin Extent =
Top = 6
Left = 274
Bottom = 125
Right = 459
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "a"
Begin Extent =
Top = 6
Left = 497
Bottom = 125
Right = 669
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "ch"
Begin Extent =
Top = 6
Left = 707
Bottom = 95
Right = 867
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "c"
Begin Extent =
Top = 6
Left = 905
Bottom = 125
Right = 1065
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "r"
Begin Extent =
Top = 96
Left = 707
Bottom = 185
Right = 867
End
DisplayFlags = 280
TopColumn = 0
End
End
End
Begin SQLPane =
End
Begin DataPane =
Begin ParameterDefaults = ""
End
Begin ColumnWidths = 9
Width = 284
Width = 1500
Width = 1500
Width = 1500
Width = 1500', #level0type = N'SCHEMA', #level0name = N'dbo', #level1type = N'VIEW', #level1name = N'vwAccountProfitCenters';
GO
EXECUTE sp_addextendedproperty #name = N'MS_DiagramPane2', #value = N'
Width = 1500
Width = 1500
Width = 1500
Width = 1500
End
End
Begin CriteriaPane =
Begin ColumnWidths = 11
Column = 1440
Alias = 900
Table = 1170
Output = 720
Append = 1400
NewValue = 1170
SortType = 1350
SortOrder = 1410
GroupBy = 1350
Filter = 1350
Or = 1350
Or = 1350
Or = 1350
End
End
End
', #level0type = N'SCHEMA', #level0name = N'dbo', #level1type = N'VIEW', #level1name = N'vwAccountProfitCenters';
GO
EXECUTE sp_addextendedproperty #name = N'MS_DiagramPaneCount', #value = 2, #level0type = N'SCHEMA', #level0name = N'dbo', #level1type = N'VIEW', #level1name = N'vwAccountProfitCenters';
GO
In SQL compare (v10 is the one I have), once you've done your table mappings, there is another tab called options. On here under the ignore section is a tick box for extended properties, tick that and then it won't matter if there are different properties on each table.
As #Tarzan mentions in a comment below:
Yes, from SSMS, go to "Tools > Options > SQL Server Object Explorer > scripting > Script extended properties = False".