Why does my STEP file cause a segmentation fault? - step

I'm writing aerodynamic design software and want to export the geometry a user specifies as a STEP file. I've managed to generate a STEP file that to my inspection appears complete, but when I try to open it with FreeCAD, I get a segmentation fault. What's wrong with my file?
I've tried changing the entity type for the edge_curve to something besides line, but I keep getting the same error. I've also tried opening the file using Solidworks, but it is also unable to open the file.
Here's the error message from FreeCAD:
Program received signal SIGSEGV, Segmentation fault.
#0 /lib/x86_64-linux-gnu/libc.so.6(+0x3ef20) [0x7f609a911f20]
#1 0x7f6009b06bd4 in StepShape_EdgeCurve::EdgeGeometry() const from /usr/lib/x86_64-linux-gnu/libTKSTEPBase.so.7+0x4
#2 0x7f600d92ae4e in StepToTopoDS_TranslateEdgeLoop::Init(opencascade::handle<StepShape_FaceBound> const&, TopoDS_Face const&, opencascade::handle<Geom_Surface> const&, opencascade::handle<StepGeom_Surface> const&, bool, StepToTopoDS_Tool&, StepToTopoDS_NMTool&) from /usr/lib/x86_64-linux-gnu/libTKSTEP.so.7+0x10de
There's more than that, but these lines seem to be the most relevant. Can anyone pinpoint where I've gone wrong?
EDIT
I've made the changes suggested and now FreeCAD will open, but nothing shows in the design space. No errors are thrown either. I'm not sure what's going on now.
ISO-10303-21;
HEADER;
FILE_DESCRIPTION ( ( 'STEP AP203' ) , '1' ) ;
FILE_NAME ( 'test_plane.stp' , '', ('Author'), (''), 'MachUpX', 'MachUpX', 'Unknown' ) ;
FILE_SCHEMA ( '' );
ENDSEC;
DATA;
#15 = SHAPE_DEFINITION_REPRESENTATION ( '', #16 , #101 ) ;
#16 = PRODUCT_DEFINITION_SHAPE ( 'test_plane' , 'NONE' , #18 ) ;
#18 = PRODUCT_DEFINITION ( 'NONE' , 'NONE' , #19 , #20 ) ;
#19 = PRODUCT_DEFINITION_FORMATION ( 'version1' , 'NONE' , #21 ) ;
#20 = PRODUCT_DEFINITION_CONTEXT ( 'NONE' , #23 , 'NONE' ) ;
#21 = PRODUCT ( 'no1' , 'test_plane' , 'Generated by MachUpX' , ( #22 ) ) ;
#22 = PRODUCT_CONTEXT ( 'NONE' , #23 , 'aeronautics' ) ;
#23 = APPLICATION_CONTEXT ( 'AP 203' ) ;
#200 = MANIFOLD_SOLID_BREP ( 'v_stab_right' , #201 ) ;
#201 = CLOSED_SHELL ( 'NONE' , ( #202 , #310 , #418 ) ) ;
#202 = ADVANCED_FACE ( 'NONE' , ( #203) , #204 , .T. ) ;
#203 = FACE_OUTER_BOUND ( 'NONE' , #209 , .T. ) ;
#204 = PLANE ( 'NONE' , #205 ) ;
#205 = AXIS2_PLACEMENT_3D ( 'NONE' , #206 , #207 , #208 ) ;
#206 = CARTESIAN_POINT ( 'NONE' , ( -3.000000 , 0.000000 , -0.100000 ) ) ;
#207 = DIRECTION ( 'NONE' , ( -1.000000 , 0.000000 , 0.000000 ) ) ;
#208 = DIRECTION ( 'NONE' , ( -0.000000 , -1.000000 , -0.000000 ) ) ;
#210 = ORIENTED_EDGE ( 'NONE' , * , * , 211 , .T. ) ;
#211 = EDGE_CURVE ( 'NONE' , #212 , #214 , #216 , .T. ) ;
#212 = VERTEX ( 'NONE' , #213 ) ;
#213 = CARTESIAN_POINT ( 'NONE' , ( -3.750000 , 0.000000 , -0.100000 ) ) ;
#214 = VERTEX ( 'NONE' , #215 ) ;
#215 = CARTESIAN_POINT ( 'NONE' , ( -3.525788 , 0.023681 , -0.100000 ) ) ;
#216 = LINE ( 'NONE' , #217 , #218 ) ;
#217 = CARTESIAN_POINT ( 'NONE' , ( -3.750000 , 0.000000 , -0.100000 ) ) ;
#218 = VECTOR ( 'NONE' , #219 , 0.2254588471561799 ) ;
#219 = DIRECTION ( 'NONE' , ( 0.994469 , 0.105034 , 0.000000 ) ) ;
#220 = ORIENTED_EDGE ( 'NONE' , * , * , 221 , .T. ) ;
#221 = EDGE_CURVE ( 'NONE' , #222 , #224 , #226 , .T. ) ;
#222 = VERTEX ( 'NONE' , #223 ) ;
#223 = CARTESIAN_POINT ( 'NONE' , ( -3.525788 , 0.023681 , -0.100000 ) ) ;
#224 = VERTEX ( 'NONE' , #225 ) ;
#225 = CARTESIAN_POINT ( 'NONE' , ( -3.301004 , 0.041113 , -0.100000 ) ) ;
#226 = LINE ( 'NONE' , #227 , #228 ) ;
#227 = CARTESIAN_POINT ( 'NONE' , ( -3.525788 , 0.023681 , -0.100000 ) ) ;
#228 = VECTOR ( 'NONE' , #229 , 0.22545914553885527 ) ;
#229 = DIRECTION ( 'NONE' , ( 0.997007 , 0.077315 , 0.000000 ) ) ;
#230 = ORIENTED_EDGE ( 'NONE' , * , * , 231 , .T. ) ;
#231 = EDGE_CURVE ( 'NONE' , #232 , #234 , #236 , .T. ) ;
#232 = VERTEX ( 'NONE' , #233 ) ;
#233 = CARTESIAN_POINT ( 'NONE' , ( -3.301004 , 0.041113 , -0.100000 ) ) ;
#234 = VERTEX ( 'NONE' , #235 ) ;
#235 = CARTESIAN_POINT ( 'NONE' , ( -3.075733 , 0.049881 , -0.100000 ) ) ;
#236 = LINE ( 'NONE' , #237 , #238 ) ;
#237 = CARTESIAN_POINT ( 'NONE' , ( -3.301004 , 0.041113 , -0.100000 ) ) ;
#238 = VECTOR ( 'NONE' , #239 , 0.22544175959974602 ) ;
#239 = DIRECTION ( 'NONE' , ( 0.999243 , 0.038895 , 0.000000 ) ) ;
#240 = ORIENTED_EDGE ( 'NONE' , * , * , 241 , .T. ) ;
#241 = EDGE_CURVE ( 'NONE' , #242 , #244 , #246 , .T. ) ;
#242 = VERTEX ( 'NONE' , #243 ) ;
#243 = CARTESIAN_POINT ( 'NONE' , ( -3.075733 , 0.049881 , -0.100000 ) ) ;
#244 = VERTEX ( 'NONE' , #245 ) ;
#245 = CARTESIAN_POINT ( 'NONE' , ( -2.850712 , 0.039123 , -0.100000 ) ) ;
#246 = LINE ( 'NONE' , #247 , #248 ) ;
#247 = CARTESIAN_POINT ( 'NONE' , ( -3.075733 , 0.049881 , -0.100000 ) ) ;
#248 = VECTOR ( 'NONE' , #249 , 0.2252781083976028 ) ;
#249 = DIRECTION ( 'NONE' , ( 0.998859 , -0.047756 , -0.000000 ) ) ;
#250 = ORIENTED_EDGE ( 'NONE' , * , * , 251 , .T. ) ;
#251 = EDGE_CURVE ( 'NONE' , #252 , #254 , #256 , .T. ) ;
#252 = VERTEX ( 'NONE' , #253 ) ;
#253 = CARTESIAN_POINT ( 'NONE' , ( -2.850712 , 0.039123 , -0.100000 ) ) ;
#254 = VERTEX ( 'NONE' , #255 ) ;
#255 = CARTESIAN_POINT ( 'NONE' , ( -2.850713 , -0.039123 , -0.100000 ) ) ;
#256 = LINE ( 'NONE' , #257 , #258 ) ;
#257 = CARTESIAN_POINT ( 'NONE' , ( -2.850712 , 0.039123 , -0.100000 ) ) ;
#258 = VECTOR ( 'NONE' , #259 , 0.07824649394376136 ) ;
#259 = DIRECTION ( 'NONE' , ( -0.000010 , -1.000000 , 0.000000 ) ) ;
#260 = ORIENTED_EDGE ( 'NONE' , * , * , 261 , .T. ) ;
#261 = EDGE_CURVE ( 'NONE' , #262 , #264 , #266 , .T. ) ;
#262 = VERTEX ( 'NONE' , #263 ) ;
#263 = CARTESIAN_POINT ( 'NONE' , ( -2.850713 , -0.039123 , -0.100000 ) ) ;
#264 = VERTEX ( 'NONE' , #265 ) ;
#265 = CARTESIAN_POINT ( 'NONE' , ( -3.075733 , -0.049881 , -0.100000 ) ) ;
#266 = LINE ( 'NONE' , #267 , #268 ) ;
#267 = CARTESIAN_POINT ( 'NONE' , ( -2.850713 , -0.039123 , -0.100000 ) ) ;
#268 = VECTOR ( 'NONE' , #269 , 0.22527736125091588 ) ;
#269 = DIRECTION ( 'NONE' , ( -0.998859 , -0.047753 , -0.000000 ) ) ;
#270 = ORIENTED_EDGE ( 'NONE' , * , * , 271 , .T. ) ;
#271 = EDGE_CURVE ( 'NONE' , #272 , #274 , #276 , .T. ) ;
#272 = VERTEX ( 'NONE' , #273 ) ;
#273 = CARTESIAN_POINT ( 'NONE' , ( -3.075733 , -0.049881 , -0.100000 ) ) ;
#274 = VERTEX ( 'NONE' , #275 ) ;
#275 = CARTESIAN_POINT ( 'NONE' , ( -3.301004 , -0.041113 , -0.100000 ) ) ;
#276 = LINE ( 'NONE' , #277 , #278 ) ;
#277 = CARTESIAN_POINT ( 'NONE' , ( -3.075733 , -0.049881 , -0.100000 ) ) ;
#278 = VECTOR ( 'NONE' , #279 , 0.22544172256288283 ) ;
#279 = DIRECTION ( 'NONE' , ( -0.999243 , 0.038895 , 0.000000 ) ) ;
#280 = ORIENTED_EDGE ( 'NONE' , * , * , 281 , .T. ) ;
#281 = EDGE_CURVE ( 'NONE' , #282 , #284 , #286 , .T. ) ;
#282 = VERTEX ( 'NONE' , #283 ) ;
#283 = CARTESIAN_POINT ( 'NONE' , ( -3.301004 , -0.041113 , -0.100000 ) ) ;
#284 = VERTEX ( 'NONE' , #285 ) ;
#285 = CARTESIAN_POINT ( 'NONE' , ( -3.525788 , -0.023681 , -0.100000 ) ) ;
#286 = LINE ( 'NONE' , #287 , #288 ) ;
#287 = CARTESIAN_POINT ( 'NONE' , ( -3.301004 , -0.041113 , -0.100000 ) ) ;
#288 = VECTOR ( 'NONE' , #289 , 0.22545905822782863 ) ;
#289 = DIRECTION ( 'NONE' , ( -0.997007 , 0.077315 , 0.000000 ) ) ;
#290 = ORIENTED_EDGE ( 'NONE' , * , * , 291 , .T. ) ;
#291 = EDGE_CURVE ( 'NONE' , #292 , #294 , #296 , .T. ) ;
#292 = VERTEX ( 'NONE' , #293 ) ;
#293 = CARTESIAN_POINT ( 'NONE' , ( -3.525788 , -0.023681 , -0.100000 ) ) ;
#294 = VERTEX ( 'NONE' , #295 ) ;
#295 = CARTESIAN_POINT ( 'NONE' , ( -3.750000 , -0.000000 , -0.100000 ) ) ;
#296 = LINE ( 'NONE' , #297 , #298 ) ;
#297 = CARTESIAN_POINT ( 'NONE' , ( -3.525788 , -0.023681 , -0.100000 ) ) ;
#298 = VECTOR ( 'NONE' , #299 , 0.22545886333367593 ) ;
#299 = DIRECTION ( 'NONE' , ( -0.994469 , 0.105034 , 0.000000 ) ) ;
#300 = ORIENTED_EDGE ( 'NONE' , * , * , 301 , .T. ) ;
#301 = EDGE_CURVE ( 'NONE' , #302 , #304 , #306 , .T. ) ;
#302 = VERTEX ( 'NONE' , #303 ) ;
#303 = CARTESIAN_POINT ( 'NONE' , ( -3.750000 , -0.000000 , -0.100000 ) ) ;
#304 = VERTEX ( 'NONE' , #305 ) ;
#305 = CARTESIAN_POINT ( 'NONE' , ( -3.750000 , 0.000000 , -0.100000 ) ) ;
#306 = LINE ( 'NONE' , #307 , #308 ) ;
#307 = CARTESIAN_POINT ( 'NONE' , ( -3.750000 , -0.000000 , -0.100000 ) ) ;
#308 = VECTOR ( 'NONE' , #309 , 8.294702139732885e-07 ) ;
#309 = DIRECTION ( 'NONE' , ( -0.007167 , 0.999974 , 0.000000 ) ) ;
#209 = EDGE_LOOP ( 'NONE' , ( #210 , #220 , #230 , #240 , #250 , #260 , #270 , #280 , #290 , #300 ) ) ;
#310 = ADVANCED_FACE ( 'NONE' , ( #311) , #312 , .T. ) ;
#311 = FACE_OUTER_BOUND ( 'NONE' , #317 , .T. ) ;
#312 = PLANE ( 'NONE' , #313 ) ;
#313 = AXIS2_PLACEMENT_3D ( 'NONE' , #314 , #315 , #316 ) ;
#314 = CARTESIAN_POINT ( 'NONE' , ( -3.000000 , 0.000000 , -2.100000 ) ) ;
#315 = DIRECTION ( 'NONE' , ( -1.000000 , 0.000000 , 0.000000 ) ) ;
#316 = DIRECTION ( 'NONE' , ( -0.000000 , -1.000000 , -0.000000 ) ) ;
#318 = ORIENTED_EDGE ( 'NONE' , * , * , 319 , .T. ) ;
#319 = EDGE_CURVE ( 'NONE' , #320 , #322 , #324 , .T. ) ;
#320 = VERTEX ( 'NONE' , #321 ) ;
#321 = CARTESIAN_POINT ( 'NONE' , ( -3.750000 , 0.000000 , -2.100000 ) ) ;
#322 = VERTEX ( 'NONE' , #323 ) ;
#323 = CARTESIAN_POINT ( 'NONE' , ( -3.525788 , 0.023681 , -2.100000 ) ) ;
#324 = LINE ( 'NONE' , #325 , #326 ) ;
#325 = CARTESIAN_POINT ( 'NONE' , ( -3.750000 , 0.000000 , -2.100000 ) ) ;
#326 = VECTOR ( 'NONE' , #327 , 0.2254588471561799 ) ;
#327 = DIRECTION ( 'NONE' , ( 0.994469 , 0.105034 , 0.000000 ) ) ;
#328 = ORIENTED_EDGE ( 'NONE' , * , * , 329 , .T. ) ;
#329 = EDGE_CURVE ( 'NONE' , #330 , #332 , #334 , .T. ) ;
#330 = VERTEX ( 'NONE' , #331 ) ;
#331 = CARTESIAN_POINT ( 'NONE' , ( -3.525788 , 0.023681 , -2.100000 ) ) ;
#332 = VERTEX ( 'NONE' , #333 ) ;
#333 = CARTESIAN_POINT ( 'NONE' , ( -3.301004 , 0.041113 , -2.100000 ) ) ;
#334 = LINE ( 'NONE' , #335 , #336 ) ;
#335 = CARTESIAN_POINT ( 'NONE' , ( -3.525788 , 0.023681 , -2.100000 ) ) ;
#336 = VECTOR ( 'NONE' , #337 , 0.22545914553885527 ) ;
#337 = DIRECTION ( 'NONE' , ( 0.997007 , 0.077315 , 0.000000 ) ) ;
#338 = ORIENTED_EDGE ( 'NONE' , * , * , 339 , .T. ) ;
#339 = EDGE_CURVE ( 'NONE' , #340 , #342 , #344 , .T. ) ;
#340 = VERTEX ( 'NONE' , #341 ) ;
#341 = CARTESIAN_POINT ( 'NONE' , ( -3.301004 , 0.041113 , -2.100000 ) ) ;
#342 = VERTEX ( 'NONE' , #343 ) ;
#343 = CARTESIAN_POINT ( 'NONE' , ( -3.075733 , 0.049881 , -2.100000 ) ) ;
#344 = LINE ( 'NONE' , #345 , #346 ) ;
#345 = CARTESIAN_POINT ( 'NONE' , ( -3.301004 , 0.041113 , -2.100000 ) ) ;
#346 = VECTOR ( 'NONE' , #347 , 0.22544175959974602 ) ;
#347 = DIRECTION ( 'NONE' , ( 0.999243 , 0.038895 , 0.000000 ) ) ;
#348 = ORIENTED_EDGE ( 'NONE' , * , * , 349 , .T. ) ;
#349 = EDGE_CURVE ( 'NONE' , #350 , #352 , #354 , .T. ) ;
#350 = VERTEX ( 'NONE' , #351 ) ;
#351 = CARTESIAN_POINT ( 'NONE' , ( -3.075733 , 0.049881 , -2.100000 ) ) ;
#352 = VERTEX ( 'NONE' , #353 ) ;
#353 = CARTESIAN_POINT ( 'NONE' , ( -2.850712 , 0.039123 , -2.100000 ) ) ;
#354 = LINE ( 'NONE' , #355 , #356 ) ;
#355 = CARTESIAN_POINT ( 'NONE' , ( -3.075733 , 0.049881 , -2.100000 ) ) ;
#356 = VECTOR ( 'NONE' , #357 , 0.2252781083976028 ) ;
#357 = DIRECTION ( 'NONE' , ( 0.998859 , -0.047756 , 0.000000 ) ) ;
#358 = ORIENTED_EDGE ( 'NONE' , * , * , 359 , .T. ) ;
#359 = EDGE_CURVE ( 'NONE' , #360 , #362 , #364 , .T. ) ;
#360 = VERTEX ( 'NONE' , #361 ) ;
#361 = CARTESIAN_POINT ( 'NONE' , ( -2.850712 , 0.039123 , -2.100000 ) ) ;
#362 = VERTEX ( 'NONE' , #363 ) ;
#363 = CARTESIAN_POINT ( 'NONE' , ( -2.850713 , -0.039123 , -2.100000 ) ) ;
#364 = LINE ( 'NONE' , #365 , #366 ) ;
#365 = CARTESIAN_POINT ( 'NONE' , ( -2.850712 , 0.039123 , -2.100000 ) ) ;
#366 = VECTOR ( 'NONE' , #367 , 0.07824649394376136 ) ;
#367 = DIRECTION ( 'NONE' , ( -0.000010 , -1.000000 , 0.000000 ) ) ;
#368 = ORIENTED_EDGE ( 'NONE' , * , * , 369 , .T. ) ;
#369 = EDGE_CURVE ( 'NONE' , #370 , #372 , #374 , .T. ) ;
#370 = VERTEX ( 'NONE' , #371 ) ;
#371 = CARTESIAN_POINT ( 'NONE' , ( -2.850713 , -0.039123 , -2.100000 ) ) ;
#372 = VERTEX ( 'NONE' , #373 ) ;
#373 = CARTESIAN_POINT ( 'NONE' , ( -3.075733 , -0.049881 , -2.100000 ) ) ;
#374 = LINE ( 'NONE' , #375 , #376 ) ;
#375 = CARTESIAN_POINT ( 'NONE' , ( -2.850713 , -0.039123 , -2.100000 ) ) ;
#376 = VECTOR ( 'NONE' , #377 , 0.22527736125091588 ) ;
#377 = DIRECTION ( 'NONE' , ( -0.998859 , -0.047753 , 0.000000 ) ) ;
#378 = ORIENTED_EDGE ( 'NONE' , * , * , 379 , .T. ) ;
#379 = EDGE_CURVE ( 'NONE' , #380 , #382 , #384 , .T. ) ;
#380 = VERTEX ( 'NONE' , #381 ) ;
#381 = CARTESIAN_POINT ( 'NONE' , ( -3.075733 , -0.049881 , -2.100000 ) ) ;
#382 = VERTEX ( 'NONE' , #383 ) ;
#383 = CARTESIAN_POINT ( 'NONE' , ( -3.301004 , -0.041113 , -2.100000 ) ) ;
#384 = LINE ( 'NONE' , #385 , #386 ) ;
#385 = CARTESIAN_POINT ( 'NONE' , ( -3.075733 , -0.049881 , -2.100000 ) ) ;
#386 = VECTOR ( 'NONE' , #387 , 0.22544172256288283 ) ;
#387 = DIRECTION ( 'NONE' , ( -0.999243 , 0.038895 , 0.000000 ) ) ;
#388 = ORIENTED_EDGE ( 'NONE' , * , * , 389 , .T. ) ;
#389 = EDGE_CURVE ( 'NONE' , #390 , #392 , #394 , .T. ) ;
#390 = VERTEX ( 'NONE' , #391 ) ;
#391 = CARTESIAN_POINT ( 'NONE' , ( -3.301004 , -0.041113 , -2.100000 ) ) ;
#392 = VERTEX ( 'NONE' , #393 ) ;
#393 = CARTESIAN_POINT ( 'NONE' , ( -3.525788 , -0.023681 , -2.100000 ) ) ;
#394 = LINE ( 'NONE' , #395 , #396 ) ;
#395 = CARTESIAN_POINT ( 'NONE' , ( -3.301004 , -0.041113 , -2.100000 ) ) ;
#396 = VECTOR ( 'NONE' , #397 , 0.22545905822782863 ) ;
#397 = DIRECTION ( 'NONE' , ( -0.997007 , 0.077315 , 0.000000 ) ) ;
#398 = ORIENTED_EDGE ( 'NONE' , * , * , 399 , .T. ) ;
#399 = EDGE_CURVE ( 'NONE' , #400 , #402 , #404 , .T. ) ;
#400 = VERTEX ( 'NONE' , #401 ) ;
#401 = CARTESIAN_POINT ( 'NONE' , ( -3.525788 , -0.023681 , -2.100000 ) ) ;
#402 = VERTEX ( 'NONE' , #403 ) ;
#403 = CARTESIAN_POINT ( 'NONE' , ( -3.750000 , -0.000000 , -2.100000 ) ) ;
#404 = LINE ( 'NONE' , #405 , #406 ) ;
#405 = CARTESIAN_POINT ( 'NONE' , ( -3.525788 , -0.023681 , -2.100000 ) ) ;
#406 = VECTOR ( 'NONE' , #407 , 0.22545886333367593 ) ;
#407 = DIRECTION ( 'NONE' , ( -0.994469 , 0.105034 , 0.000000 ) ) ;
#408 = ORIENTED_EDGE ( 'NONE' , * , * , 409 , .T. ) ;
#409 = EDGE_CURVE ( 'NONE' , #410 , #412 , #414 , .T. ) ;
#410 = VERTEX ( 'NONE' , #411 ) ;
#411 = CARTESIAN_POINT ( 'NONE' , ( -3.750000 , -0.000000 , -2.100000 ) ) ;
#412 = VERTEX ( 'NONE' , #413 ) ;
#413 = CARTESIAN_POINT ( 'NONE' , ( -3.750000 , 0.000000 , -2.100000 ) ) ;
#414 = LINE ( 'NONE' , #415 , #416 ) ;
#415 = CARTESIAN_POINT ( 'NONE' , ( -3.750000 , -0.000000 , -2.100000 ) ) ;
#416 = VECTOR ( 'NONE' , #417 , 8.294702139732885e-07 ) ;
#417 = DIRECTION ( 'NONE' , ( -0.007167 , 0.999974 , 0.000000 ) ) ;
#317 = EDGE_LOOP ( 'NONE' , ( #318 , #328 , #338 , #348 , #358 , #368 , #378 , #388 , #398 , #408 ) ) ;
#419 = CARTESIAN_POINT ( 'NONE' , ( -3.750000 , 0.000000 , -0.100000 ) ) ;
#420 = CARTESIAN_POINT ( 'NONE' , ( -3.525788 , 0.023681 , -0.100000 ) ) ;
#421 = CARTESIAN_POINT ( 'NONE' , ( -3.301004 , 0.041113 , -0.100000 ) ) ;
#422 = CARTESIAN_POINT ( 'NONE' , ( -3.075733 , 0.049881 , -0.100000 ) ) ;
#423 = CARTESIAN_POINT ( 'NONE' , ( -2.850712 , 0.039123 , -0.100000 ) ) ;
#424 = CARTESIAN_POINT ( 'NONE' , ( -2.850713 , -0.039123 , -0.100000 ) ) ;
#425 = CARTESIAN_POINT ( 'NONE' , ( -3.075733 , -0.049881 , -0.100000 ) ) ;
#426 = CARTESIAN_POINT ( 'NONE' , ( -3.301004 , -0.041113 , -0.100000 ) ) ;
#427 = CARTESIAN_POINT ( 'NONE' , ( -3.525788 , -0.023681 , -0.100000 ) ) ;
#428 = CARTESIAN_POINT ( 'NONE' , ( -3.750000 , -0.000000 , -0.100000 ) ) ;
#429 = CARTESIAN_POINT ( 'NONE' , ( -3.750000 , 0.000000 , -2.100000 ) ) ;
#430 = CARTESIAN_POINT ( 'NONE' , ( -3.525788 , 0.023681 , -2.100000 ) ) ;
#431 = CARTESIAN_POINT ( 'NONE' , ( -3.301004 , 0.041113 , -2.100000 ) ) ;
#432 = CARTESIAN_POINT ( 'NONE' , ( -3.075733 , 0.049881 , -2.100000 ) ) ;
#433 = CARTESIAN_POINT ( 'NONE' , ( -2.850712 , 0.039123 , -2.100000 ) ) ;
#434 = CARTESIAN_POINT ( 'NONE' , ( -2.850713 , -0.039123 , -2.100000 ) ) ;
#435 = CARTESIAN_POINT ( 'NONE' , ( -3.075733 , -0.049881 , -2.100000 ) ) ;
#436 = CARTESIAN_POINT ( 'NONE' , ( -3.301004 , -0.041113 , -2.100000 ) ) ;
#437 = CARTESIAN_POINT ( 'NONE' , ( -3.525788 , -0.023681 , -2.100000 ) ) ;
#438 = CARTESIAN_POINT ( 'NONE' , ( -3.750000 , -0.000000 , -2.100000 ) ) ;
#418 = B_SPLINE_SURFACE_WITH_KNOTS ( 'NONE' , 3 , 3 , ( ( #419 , #420 , #421 , #422 , #423 , #424 , #425 , #426 , #427 , #428 ), ( #429 , #430 , #431 , #432 , #433 , #434 , #435 , #436 , #437 , #438 ) ) , .UNSPECIFIED. , .F. , .F. , .F. , .UNSPECIFIED. , .UNSPECIFIED. , ( 0.0, 1.0 ) , ( 0.0, 0.1111111111111111, 0.2222222222222222, 0.3333333333333333, 0.4444444444444444, 0.5555555555555556, 0.6666666666666666, 0.7777777777777777, 0.8888888888888888, 1.0 ) , .UNSPECIFIED.) ;
#101 = ADVANCED_BREP_SHAPE_REPRESENTATION ( 'NONE' , ( #200 ) , #103 ) ;
#103 = GEOMETRIC_REPRESENTATION_CONTEXT ( 3 ) ;
ENDSEC;
END-ISO-10303-21;

FreeCAD relies on Open CASCADE Technology (OCCT) library for reading STEP file.
If you will open your STEP file in CAD Assistant (free 3D viewer based on OCCT) you will see the following output in Message Window generated by OCCT reader:
20:29 Errors on Reading Header Entity N0.6:HeaderSection_FileSchema
20:29 Parameter #1 (schema_identifiers) is not a LIST
Error occurred transferring STEP file!
C:/test.stp
20:29 Count STEP Reader Failures for 'test.stp'
----- -----------
1 F: Parameter #1 (schema_identifiers) is not a LIST
1 F:SHAPE_DEFINITION_REPRESENTATION: Count of Parameters is not 2 for shape_definition_representation
1 F:CLOSED_SHELL: Parameter n0.3 (face) : Entity has illegal type
20 F:ORIENTED_EDGE: Parameter n0.4 (edge_element) not an Entity
40 F:VERTEX: Count of Parameters is not 1 for vertex
1 F:B_SPLINE_SURFACE_WITH_KNOTS: Parameter n0.9 (u_multiplicities) not a LIST
1 F:B_SPLINE_SURFACE_WITH_KNOTS: Parameter n0.10 (v_multiplicities) not a LIST
1 F:GEOMETRIC_REPRESENTATION_CONTEXT: Count of Parameters is not 3 for geometric_representation_context
Nb Total:66 for 8 items
These message could help to figure out what is wrong in STEP file, or at least what OCCT reader dislikes in the file.
There is a question, though, why writing STEP writer from the scratch and not using some existing library? I suppose that geometry structure to be exported is rather simple to make an own STEP writer worth efforts.

Related

Power BI - SQL: Incorrect syntax near the keyword 'DECLARE'. Incorrect syntax near ')'

New to SQL and was given the query below to use in Power BI. It pulls the data table correctly on preview but fails when applying the change into Power BI Desktop. I don't know how to fix the syntax.
I get this error:
Power BI - SQL: Incorrect syntax near the keyword 'DECLARE'. Incorrect syntax near ')'.
Here is the query:
DECLARE #CLIENT AS NVARCHAR(32)
DECLARE #FULLVERSION AS NVARCHAR(10)
DECLARE #DATERUN AS DATETIME
DECLARE #ANON AS INT --1 to set anonymised mode on, 0 to set it to off
DECLARE #FROMDATE AS DATE --(FORMAT = YYYYMMDD) --UPDATE
DECLARE #TODATE AS DATE --(FORMAT = YYYYMMDD) --UPDATE
SET #CLIENT = 'HOGANS'
--SET #FULLVERSION = (SELECT MAX(BH_Version) FROM BH_Version)
SET #DATERUN = ( Getdate() )
SET #ANON = 0
SET #FROMDATE = '20211101' --(FORMAT = YYYYMMDD) --UPDATE
SET #TODATE = '20211231' --(FORMAT = YYYYMMDD) --UPDATE
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET nocount ON;
-- Insert statements for procedure here
SELECT #Client AS
ClientName,
#DATERUN AS DateRun,
#FROMDATE AS
QueryVariable_FromDate,
#TODATE AS
QueryVariable_ToDate,
-- #FULLVERSION as BHVersionWhenRun,
T.bh_taskguid,
RIGHT(Datepart(yy, T.bh_creationdate), 2)
+ RIGHT('00'+ CONVERT(NVARCHAR(2), Datepart(mm, T.bh_creationdate)), 2)
+ '-' + CONVERT(NVARCHAR, T.bh_referenceid) AS TaskID,
Auth.bh_userguid AS
AuthorGUID,
CASE
WHEN #ANON = 0 THEN Auth.bh_username
WHEN #ANON = 1 THEN NULL
END AS
AuthorName,
AuthDept.bh_departmentname AS
AuthorDepartmentName,
(SELECT TOP 1 AD.bh_departmentname
FROM bh_historic_report_departments AS AD
WHERE AuthDept.bh_parentguid = AD.bh_departmentguid) AS
AuthorDepartmentParent,
--THIS CHECKS THE HISTORIC DEPT STRUCTURE TO GET THE NAME OF THE PARENT DEPARTMENT OF THE AUTHOR
Sec.bh_userguid AS
CompletedByGUID,
CASE
WHEN #ANON = 0 THEN Sec.bh_username
WHEN #ANON = 1 THEN NULL
END AS
CompletedByName,
SecDept.bh_departmentname AS
CompletedByDepartmentName,
(SELECT TOP 1 SD.bh_departmentname
FROM bh_historic_report_departments AS SD
WHERE SecDept.bh_parentguid = SD.bh_departmentguid) AS
SecDepartmentParent,
--THIS CHECKS THE HISTORIC DEPT STRUCTURE TO GET THE NAME OF THE PARENT DEPARTMENT OF THE SECRETARY
CASE
WHEN #ANON = 0 THEN (SELECT TOP 1 HU.bh_username
--BH_UserGuid and remove the join for GUID only
FROM bh_historic_report_taskaudit HTA
INNER JOIN bh_historic_report_users AS HU
ON ( HU.bh_userguid =
HTA.bh_userguid )
WHERE ( HTA.bh_taskguid = T.bh_taskguid )
ORDER BY bh_auditid ASC)
WHEN #ANON = 1 THEN NULL
END AS
'Submitted By (Name)',
(SELECT TOP 1 bh_userguid
FROM bh_historic_report_taskaudit
WHERE ( bh_taskguid = T.bh_taskguid )
ORDER BY bh_auditid ASC) AS
'Submitted By (GUID)',
(SELECT bh_username
FROM bh_locks
WHERE bh_objectguid = t.bh_taskguid) AS
'Locked By',
CASE
WHEN (SELECT bh_username
FROM bh_locks
WHERE bh_objectguid = t.bh_taskguid) IS NULL THEN 'Pending'
WHEN Sec.bh_userguid IS NULL THEN 'In Progress'
ELSE 'Complete'
END AS
'TaskStatus',
CASE
WHEN (SELECT TOP 1 bh_userguid
FROM bh_historic_report_taskaudit
WHERE ( bh_taskguid = T.bh_taskguid )
ORDER BY bh_auditid ASC) = Auth.bh_userguid THEN 'Author'
ELSE 'On Behalf'
END AS
'Logged by',
WF.bh_workflowname AS
WorkflowName,
CASE
WHEN DT.bh_workflowname IS NOT NULL THEN DT.bh_workflowname
ELSE 'Not Configured'
END AS
'Work Type Should Go To',
CASE
WHEN ( DT.bh_workflowguid = T.bh_workflowguid ) THEN 'Correct Workflow'
--If no default workflow is specified then we assume this is sent to the correct workflow.
WHEN ( DT.bh_workflowguid IS NULL ) THEN 'No Default Workflow'
ELSE 'Incorrect Workflow'
END AS
'Sent To Correct Workflow',
-- ONLY POSSIBLE ON V5 AND ABOVE
CASE
WHEN ( T.bh_source = '15' ) -- Sent from Forms Desktop Assistant
--OR the below which includes iOS (10, 11), Android (12), Now Mail (4) and Hub (18)
OR ( T.bh_lengthintenths = '0'
AND T.bh_source IN ( '18', '10', '11', '12', '4' ) )
--AND T.BH_DocumentType NOT IN (SELECT BH_DocumentTypeName FROM BH_DocumentTypes)) -- assuming that if WT no longer exists and is zero length and is sent from Hub (i.e. not from Mobile, Classic etc which can't send Now tasks) then NOW
THEN 'TASK'
ELSE 'VOICE'
END AS
'Task Type (TASK or VOICE)',
--FOR V4, MANUALLY APPLYING ALL VOICE AS TASK TYPE
-- 'VOICE' as 'Task Type (NOW or VOICE)',
CASE
WHEN #ANON = 0 THEN T.bh_title
WHEN #ANON = 1 THEN NULL
ELSE NULL
END AS
'BH_Title',
T.bh_documenttype AS WorkType
,
T.bh_creationdate,
T.bh_senddate,
T.bh_sentpriority,
CASE
WHEN TA.priorities > 1 THEN 'YES'
ELSE 'NO'
END AS
'PriorityChanged',
T.bh_completiondate,
CASE
WHEN ( T.bh_requiredby IS NOT NULL )
AND ( T.bh_completiondate <= T.bh_requiredby ) THEN 'On Time'
WHEN ( T.bh_requiredby IS NOT NULL )
AND ( T.bh_completiondate > T.bh_requiredby ) THEN 'Overdue'
WHEN T.bh_requiredby IS NULL THEN 'No Deadline Set'
END AS OnTime,
T.bh_priorityname,
T.bh_requiredby,
CASE
WHEN TA.requiredby > 1 THEN 'YES'
ELSE 'NO'
END AS
'RequiredByChanged',
T.bh_sourcetimezone AS
TimeZoneOffset,
T.bh_turnaroundtime AS
TurnaroundTimeInSec,
--NOTE: this is the difference in seconds between the send date and the completion date
-- (
-- RIGHT('000' + CONVERT(VARCHAR, T.BH_TurnaroundTime / 3600 / 24),3) + ':'
-- + RIGHT('00' + CONVERT(VARCHAR, T.BH_TurnaroundTime / 3600 % 24),2) + ':'
-- + RIGHT('00' + CONVERT(VARCHAR, T.BH_TurnaroundTime / 60 % 60),2) + ':'
-- + RIGHT('00' + CONVERT(VARCHAR,T.BH_TurnaroundTime % 60),2)
-- ) AS TurnaroundTimeDays,
T.bh_numreassignments,
CASE
WHEN ( T.bh_source = '0' ) THEN 'Classic Client'
WHEN ( T.bh_source = '4' ) THEN 'Now Mail'
WHEN ( T.bh_source = '5' ) THEN 'Web Client'
WHEN ( T.bh_source = '6' ) THEN 'Windows Mobile'
WHEN ( T.bh_source = '7' ) THEN 'BlackBerry'
WHEN ( T.bh_source = '8' ) THEN 'Hosted Services Client'
WHEN ( T.bh_source = '9' ) THEN 'Work Manager'
WHEN ( T.bh_source = '10' ) THEN 'BigHand Go'
WHEN ( T.bh_source = '11' ) THEN 'BigHand Mobile iPhone'
WHEN ( T.bh_source = '12' ) THEN 'Android'
WHEN ( T.bh_source = '13' ) THEN 'BlackBerry 10'
WHEN ( T.bh_source = '14' ) THEN 'Windows Phone'
WHEN ( T.bh_source = '15' ) THEN 'BigHand Now'
WHEN ( T.bh_source = '16' ) THEN 'BigHand Go For Windows'
WHEN ( T.bh_source = '17' ) THEN 'BigHand Go For Windows Phone'
WHEN ( T.bh_source = '18' ) THEN 'Hub'
END AS 'Source'
,
T.bh_sourcetimezone,
--(
-- RIGHT('00' + CONVERT(VARCHAR, (T.BH_LengthInTenths/10) / 3600 % 24),2) + ':'
-- + RIGHT('00' + CONVERT(VARCHAR, (T.BH_LengthInTenths/10) / 60 % 60),2) + ':'
-- + RIGHT('00' + CONVERT(VARCHAR,(T.BH_LengthInTenths/10) % 60),2)
-- ) AS LengthInHours,
( T.bh_lengthintenths / 10 ) AS
LengthInSeconds,
( T.bh_lengthintenths / 10 ) / 60 AS
LengthInMins,
(SELECT Sum(Datediff(second, bh_startdate, bh_enddate))
FROM bh_historic_report_taskaudit
WHERE ( bh_taskguid = T.bh_taskguid )) AS
'Total Processing Time (Sec)',
--(
-- RIGHT('00' + CONVERT(VARCHAR, (SELECT sum(datediff(SECOND,BH_StartDate, BH_EndDate))
-- FROM BH_HISTORIC_REPORT_TASKAUDIT
-- WHERE (BH_TaskGuid = T.BH_TaskGuid) AND BH_StartDate >= T.BH_SendDate) / 3600 % 24),2) + ':'
--+ RIGHT('00' + CONVERT(VARCHAR, (SELECT sum(datediff(SECOND,BH_StartDate, BH_EndDate))
-- FROM BH_HISTORIC_REPORT_TASKAUDIT
-- WHERE (BH_TaskGuid = T.BH_TaskGuid) AND BH_StartDate >= T.BH_SendDate) / 60 % 60),2) + ':'
--+ RIGHT('00' + CONVERT(VARCHAR,(SELECT sum(datediff(SECOND,BH_StartDate, BH_EndDate))
-- FROM BH_HISTORIC_REPORT_TASKAUDIT
-- WHERE (BH_TaskGuid = T.BH_TaskGuid) AND BH_StartDate >= T.BH_SendDate) % 60),2)
--) AS TotalProcessingHours,
( Isnull((SELECT Sum(Datediff(second, bh_startdate, bh_enddate))
FROM bh_historic_report_taskaudit
WHERE ( bh_taskguid = T.bh_taskguid )
AND ( bh_userguid = T.bh_authorguid )), 0) ) AS
'Author Processing Time (Sec)',
--(ISNULL((
-- RIGHT('00' + CONVERT(VARCHAR, (SELECT sum(datediff(SECOND,BH_StartDate, BH_EndDate))
-- FROM BH_HISTORIC_REPORT_TASKAUDIT
-- WHERE (BH_TaskGuid = T.BH_TaskGuid) AND (BH_UserGuid = T.BH_AuthorGuid) AND (BH_StartDate >= T.BH_SendDate)) / 3600 % 24),2) + ':'
-- + RIGHT('00' + CONVERT(VARCHAR, (SELECT sum(datediff(SECOND,BH_StartDate, BH_EndDate))
-- FROM BH_HISTORIC_REPORT_TASKAUDIT
-- WHERE (BH_TaskGuid = T.BH_TaskGuid) AND (BH_UserGuid = T.BH_AuthorGuid) AND (BH_StartDate >= T.BH_SendDate)) / 60 % 60),2) + ':'
-- + RIGHT('00' + CONVERT(VARCHAR,(SELECT sum(datediff(SECOND,BH_StartDate, BH_EndDate))
-- FROM BH_HISTORIC_REPORT_TASKAUDIT
-- WHERE (BH_TaskGuid = T.BH_TaskGuid) AND (BH_UserGuid = T.BH_AuthorGuid) AND (BH_StartDate >= T.BH_SendDate)) % 60),2)), '00:00:00')
-- ) AS AuthorProcessingHours,
( Isnull((SELECT Sum(Datediff(second, bh_startdate, bh_enddate))
FROM bh_historic_report_taskaudit
WHERE ( bh_taskguid = T.bh_taskguid )
AND ( bh_userguid <> T.bh_authorguid )
AND ( bh_startdate >= T.bh_senddate )), 0) ) AS
'Non-Author Processing Time (Sec)',
--(ISNULL((
-- RIGHT('00' + CONVERT(VARCHAR, (SELECT sum(datediff(SECOND,BH_StartDate, BH_EndDate))
-- FROM BH_HISTORIC_REPORT_TASKAUDIT
-- WHERE (BH_TaskGuid = T.BH_TaskGuid) AND (BH_UserGuid <> T.BH_AuthorGuid) AND (BH_StartDate >= T.BH_SendDate)) / 3600 % 24),2) + ':'
--+ RIGHT('00' + CONVERT(VARCHAR, (SELECT sum(datediff(SECOND,BH_StartDate, BH_EndDate))
-- FROM BH_HISTORIC_REPORT_TASKAUDIT
-- WHERE (BH_TaskGuid = T.BH_TaskGuid) AND (BH_UserGuid <> T.BH_AuthorGuid) AND (BH_StartDate >= T.BH_SendDate)) / 60 % 60),2) + ':'
--+ RIGHT('00' + CONVERT(VARCHAR,(SELECT sum(datediff(SECOND,BH_StartDate, BH_EndDate))
-- FROM BH_HISTORIC_REPORT_TASKAUDIT
-- WHERE (BH_TaskGuid = T.BH_TaskGuid) AND (BH_UserGuid <> T.BH_AuthorGuid) AND (BH_StartDate >= T.BH_SendDate)) % 60),2)), '00:00:00')
--) AS NonAuthorProcessingHours,
(SELECT Sum(bh_playtime)
FROM bh_historic_report_taskaudit
WHERE ( bh_taskguid = T.bh_taskguid )
AND ( bh_startdate >= T.bh_senddate )) AS
'TotalPlay Time',
--(
-- RIGHT('00' + CONVERT(VARCHAR, (SELECT sum(BH_PlayTime)
-- FROM BH_HISTORIC_REPORT_TASKAUDIT
-- WHERE (BH_TaskGuid = T.BH_TaskGuid) AND (BH_StartDate >= T.BH_SendDate)) / 3600 % 24),2) + ':'
--+ RIGHT('00' + CONVERT(VARCHAR, (SELECT sum(BH_PlayTime)
-- FROM BH_HISTORIC_REPORT_TASKAUDIT
-- WHERE (BH_TaskGuid = T.BH_TaskGuid) AND (BH_StartDate >= T.BH_SendDate)) / 60 % 60),2) + ':'
--+ RIGHT('00' + CONVERT(VARCHAR,(SELECT sum(BH_PlayTime)
-- FROM BH_HISTORIC_REPORT_TASKAUDIT
-- WHERE (BH_TaskGuid = T.BH_TaskGuid) AND (BH_StartDate >= T.BH_SendDate)) % 60),2)
--) AS TotalPlaytimeHours,
( Isnull((SELECT Sum(bh_playtime)
FROM bh_historic_report_taskaudit
WHERE ( bh_taskguid = T.bh_taskguid )
AND ( bh_userguid = T.bh_authorguid )
AND ( bh_startdate >= T.bh_senddate )), 0) ) AS
'Author Play Time (Sec)',
-- (ISNULL((
-- RIGHT('00' + CONVERT(VARCHAR, (SELECT sum(BH_PlayTime)
-- FROM BH_HISTORIC_REPORT_TASKAUDIT
-- WHERE (BH_TaskGuid = T.BH_TaskGuid) AND (BH_UserGuid = T.BH_AuthorGuid) AND (BH_StartDate >= T.BH_SendDate)) / 3600 % 24),2) + ':'
-- + RIGHT('00' + CONVERT(VARCHAR, (SELECT sum(BH_PlayTime)
-- FROM BH_HISTORIC_REPORT_TASKAUDIT
-- WHERE (BH_TaskGuid = T.BH_TaskGuid) AND (BH_UserGuid = T.BH_AuthorGuid) AND (BH_StartDate >= T.BH_SendDate)) / 60 % 60),2) + ':'
-- + RIGHT('00' + CONVERT(VARCHAR,(SELECT sum(BH_PlayTime)
-- FROM BH_HISTORIC_REPORT_TASKAUDIT
-- WHERE (BH_TaskGuid = T.BH_TaskGuid) AND (BH_UserGuid = T.BH_AuthorGuid) AND (BH_StartDate >= T.BH_SendDate)) % 60),2)), '00:00:00' )
-- ) AS AuthorPlaytimeHours,
( Isnull((SELECT Sum(bh_playtime)
FROM bh_historic_report_taskaudit
WHERE ( bh_taskguid = T.bh_taskguid )
AND ( bh_userguid <> T.bh_authorguid )
AND ( bh_startdate >= T.bh_senddate )), 0) ) AS
'Non-Author Play Time (Sec)'
--(ISNULL((
-- RIGHT('00' + CONVERT(VARCHAR, (SELECT sum(BH_PlayTime)
-- FROM BH_HISTORIC_REPORT_TASKAUDIT
-- WHERE (BH_TaskGuid = T.BH_TaskGuid) AND (BH_UserGuid <> T.BH_AuthorGuid) AND (BH_StartDate >= T.BH_SendDate)) / 3600 % 24),2) + ':'
--+ RIGHT('00' + CONVERT(VARCHAR, (SELECT sum(BH_PlayTime)
-- FROM BH_HISTORIC_REPORT_TASKAUDIT
-- WHERE (BH_TaskGuid = T.BH_TaskGuid) AND (BH_UserGuid <> T.BH_AuthorGuid) AND (BH_StartDate >= T.BH_SendDate)) / 60 % 60),2) + ':'
--+ RIGHT('00' + CONVERT(VARCHAR,(SELECT sum(BH_PlayTime)
-- FROM BH_HISTORIC_REPORT_TASKAUDIT
-- WHERE (BH_TaskGuid = T.BH_TaskGuid) AND (BH_UserGuid <> T.BH_AuthorGuid) AND (BH_StartDate >= T.BH_SendDate)) % 60),2)
--), '00:00:00')) AS NonAuthorPlaytimeHours,
FROM bh_historic_report_tasks AS T
INNER JOIN bh_historic_report_users AS Auth
ON ( T.bh_authorguid = Auth.bh_userguid )
LEFT OUTER JOIN bh_historic_report_users AS Sec
ON ( T.bh_completedby = Sec.bh_userguid )
INNER JOIN bh_historic_report_departments AS AuthDept
ON ( T.bh_authordept = AuthDept.bh_departmentguid )
LEFT OUTER JOIN bh_historic_report_departments AS SecDept
ON ( T.bh_completedbydept = SecDept.bh_departmentguid )
INNER JOIN bh_historic_report_workflows AS WF
ON ( T.bh_workflowguid = WF.bh_workflowguid )
LEFT OUTER JOIN (SELECT NULL AS Availability,
A.bh_documenttypeguid,
A.bh_documenttypename,
A.bh_workflowguid,
WF.bh_workflowname,
A.bh_usage
FROM bh_documenttypes AS A
INNER JOIN bh_historic_report_workflows AS WF
ON ( A.bh_workflowguid =
WF.bh_workflowguid )
WHERE ( bh_isglobal = '1'
AND bh_deleted = 0
AND bh_disabled = 0 )
UNION
SELECT DocTypeDept.bh_departmentguid AS Availability,
DOCTYPE.bh_documenttypeguid,
DOCTYPE.bh_documenttypename,
DOCTYPE.bh_workflowguid,
WFLOW.bh_workflowname,
DOCTYPE.bh_usage
FROM bh_documenttypebydepartment AS DOCTYPEDEPT
INNER JOIN bh_documenttypes AS DOCTYPE
ON ( DOCTYPE.bh_documenttypeguid =
DOCTYPEDEPT.bh_documenttypeguid )
LEFT OUTER JOIN bh_historic_report_workflows AS
WFLOW
ON ( DOCTYPE.bh_workflowguid =
WFLOW.bh_workflowguid )
WHERE DOCTYPEDEPT.bh_departmentguid IN
(SELECT DISTINCT tempT.bh_authordept
FROM
bh_historic_report_tasks AS TempT
WHERE
--TempT.BH_SendDate >='20170901'
TempT.bh_completiondate >= #FROMDATE
--Only include tasks sent after a certain date (FORMAT = YYYYMMDD)
AND TempT.bh_completiondate < #TODATE
--Only include tasks sent after a certain date (FORMAT = YYYYMMDD)
)
AND DOCTYPE.bh_deleted = 0
AND DOCTYPE.bh_disabled = 0) AS DT
ON ( T.bh_documenttype = DT.bh_documenttypename )
AND ( ( DT.availability = AuthDept.bh_departmentguid )
OR ( DT.availability IS NULL ) )
AND ( DT.bh_usage = ( CASE
WHEN ( T.bh_source = '15' )
-- Sent from Now client
OR ( T.bh_lengthintenths =
'0'
AND T.bh_source = '18'
)
----OR sent from Hub and zero length
THEN '2' --NOW TYPE
ELSE '1' --VOICE TYPE
END ) )
--Joining on latest Audit row for the task so can return things like the latest Workflow stage etc.
INNER JOIN (SELECT bh_taskguid,
Max(bh_auditid) AS AuditID,
Count(DISTINCT bh_requiredby) RequiredBy,
Count(DISTINCT bh_priorityname) Priorities
FROM bh_historic_report_taskaudit
GROUP BY bh_taskguid) TA
ON T.bh_taskguid = TA.bh_taskguid
INNER JOIN bh_historic_report_taskaudit TAUD
ON TA.auditid = TAUD.bh_auditid
WHERE
--T.BH_CompletionDate IS NOT NULL --Include completed tasks only AND
--T.BH_CompletedByDept IS NOT NULL--Excludes Drafts created but not submitted--changed from--AND SecDept.BH_DepartmentName IS NOT NULL AND
T.bh_completiondate >= #FROMDATE
--Only include tasks created after a certain date (FORMAT = YYYYMMDD)
AND T.bh_completiondate < #TODATE
--Only include tasks created after a certain date (FORMAT = YYYYMMDD)
AND TAUD.bh_startdate >= Dateadd(month, -1, #FROMDATE)
AND TAUD.bh_startdate <= Dateadd(month, 1, #TODATE) --only includes processing audit times for activities started within 1 month prior to and post the Completion Date range
Power BI constructs a query like this:
select * from ( ... your query goes here ... ) as SourceQuery
So when it puts your query between the parenthesis, it isn't a valid query anymore. Power BI does that, because it needs to be able to add joins and filters to your query. Either rebuild the logic inside Power BI using M and DAX, or put your query in a view/UDF in the data source and select from it.

Run TSQL script on Redshift

I have a script that I once created and have been using on TSQL for years. It creates a calendar dimension.
I converted my script from T-SQL to Redshift using http://www.sqlines.com/online. I executed it through DBeaver. It throws all kinds of errors.
I tried correcting it but then found out Redshift does not support variables.
Does anyone know whether (and if so, how) I can execute the script below on Redshift?
The script below is pure T-SQL, do not hesitate to use it, change it, improve it out- or inside the context of this question.
Parts of it are dutch but using the translations below you should be easily able to understand what it is doing
dag = day
maand = month
jaar = year
werkdag = workingday
lang = long
kort = short
teller = counter
naam = name
feestdag = holiday
set nocount on
declare #begindatum as datetime = dateadd(year,-150,getdate())
declare #aantal_jaren as int = 1 -- betekent x - 100 jaren in de toekomst
declare #einddatum as datetime = dateadd(year,#aantal_jaren,#begindatum)
declare #rondedatum as datetime = #begindatum
declare #print as varchar(max)
set language dutch
select 'Start', getdate()
Declare #kalender as table (
[PeriodeID] [int] NOT NULL,
[Datum] [date] NOT NULL,
[DatumMedium] [varchar](25) NULL,
[DatumLang] [varchar](25) NULL,
[DatumExtraLangNOT] [varchar](25) NULL,
[DatumVoluit] [varchar](50) NULL,
[DagVanJaar] [int] NULL,
[DagVanWeek] [int] NULL,
[DagVanMaand] [int] NULL,
[DagNaamKort] [nvarchar](4000) NULL,
[DagNaamLang] [nvarchar](30) NULL,
[WerkDag] [int] NULL,
[Weekend] [int] NOT NULL,
[Feestdag] [varchar](25) NULL,
[Werkdagteller] [int] NOT NULL,
[WeekNr] [int] NULL,
[Iso_WeekNr] [int] NULL,
[Maand] [int] NULL,
[MaandNaamKort] [nvarchar](30) NULL,
[MaandNaamLang] [nvarchar](4000) NULL,
[Kwartaal] [int] NULL,
[KwartaalNaamKort] [varchar](2) NULL,
[KwartaalNaamLang] [varchar](25) NULL,
[Jaar] [int] NOT NULL,
[JaarKwartaal] int NULL,
[JaarKwartaalNaam] [varchar](7) NULL,
[JaarWeek] [int] NULL,
[JaarWeekNaam] [varchar](25) NULL,
[JaarIso_Week] [int] NULL,
[JaarIso_WeekNaam] [varchar](25) NULL,
[JaarMaand] [int] NULL,
[JaarMaandNaamKort] [varchar](25) NULL,
[JaarMaandNaamMedium] [varchar](25) NULL,
[JaarMaandNaamLang] [varchar](25) NULL,
PRIMARY KEY (PeriodeID)
)
While #rondedatum <= #einddatum
BEGIN
Insert into #kalender
SELECT
cast(#rondedatum as int) as PeriodeID
,cast(#rondedatum as date) as Datum
,cast(DATEPART ( Day , #rondedatum ) as varchar(2)) + ' ' + Format(#rondedatum,'MMM') + ' '+ cast(year(#rondedatum) as varchar(4)) as DDMMMJJJJ
,cast(DATEPART ( Day , #rondedatum ) as varchar(2)) + ' ' + Format(#rondedatum,'MMMM') + ' '+ cast(year(#rondedatum) as varchar(4)) as DatumLang
,Format(#rondedatum,'ddd') + ' ' +cast(DATEPART ( Day , #rondedatum ) as varchar(2)) + ' ' + Format(#rondedatum,'MMMM') + cast(year(#rondedatum) as varchar(4)) as DatumExtraLang
,DATENAME(dw,#rondedatum) + ' ' +cast(DATEPART ( Day , #rondedatum ) as varchar(2)) + ' ' + Format(#rondedatum,'MMMM') + ' '+cast(year(#rondedatum) as varchar(4)) as DatumVoluit
,DATEPART ( DAYOFYEAR , #rondedatum ) as DagVanJaar
,DATEPART ( WEEKDAY , #rondedatum ) as DagVanWeek
,DATEPART ( Day , #rondedatum ) as DagVanMaand
,Format(#rondedatum,'ddd') as DagNaamKort
,DATENAME(dw,#rondedatum) as DagNaamLang
,IIF(DATEPART ( WEEKDAY , #rondedatum ) >=1 AND DATEPART ( WEEKDAY , #rondedatum ) <= 5,1,0) as WerkDag
,IIF(DATEPART ( WEEKDAY , #rondedatum ) in (6,7),1,0) as Weekend
,'' as Feestdag
, 0 as Werkdagteller
,DATEPART ( WEEK , #rondedatum ) as WeekNr
,DATEPART ( ISO_WEEK , #rondedatum ) as Iso_WeekNr
,DATEPART ( MONTH , #rondedatum ) as Maand
,Format(#rondedatum,'MMM') as MaandNaamKort
,DATENAME(mm,#rondedatum) as MaandNaamLang
,DATEPART ( QUARTER , #rondedatum ) as Kwartaal
,'K' + cast(DATEPART ( QUARTER , #rondedatum ) as varchar(1)) as KwartaalNaamKort
,cast(DATEPART ( YEAR , #rondedatum ) as varchar(4)) + ' K' + cast(DATEPART ( QUARTER , #rondedatum ) as varchar(1)) as KwartaalNaamLang
,DATEPART ( YEAR , #rondedatum ) as Jaar
,DATEPART ( YEAR , #rondedatum ) *100 + DATEPART ( QUARTER , #rondedatum ) as JaarKwartaal
,cast(DATEPART ( YEAR , #rondedatum ) as varchar(4)) + ' K' + cast(DATEPART ( QUARTER , #rondedatum ) as varchar(1)) as JaarKwartaalNaam
,DATEPART ( YEAR , #rondedatum )*100+ DATEPART ( WEEK , #rondedatum ) as JaarWeek
,Cast(DATEPART ( YEAR , #rondedatum ) as varchar(4)) + ' - ' + cast(DATEPART ( WEEK , #rondedatum ) as varchar(2)) as JaarWeekNaam
,DATEPART ( YEAR , #rondedatum )*100+ DATEPART ( ISO_WEEK , #rondedatum ) as JaarIso_Week
,Cast(DATEPART ( YEAR , #rondedatum ) as varchar(4)) + ' - ' + cast(DATEPART ( iso_WEEK , #rondedatum ) as varchar(2)) as JaarIso_WeekNaam
,DATEPART ( YEAR , #rondedatum )*100+ DATEPART ( MONTH , #rondedatum ) as JaarMaand
,Cast(DATEPART ( YEAR , #rondedatum ) as varchar(4)) + ' - ' + cast(DATEPART ( MONTH , #rondedatum ) as varchar(2)) as JaarMaandNaamKort
,Format(#rondedatum,'MMM') + ' '+ Cast(DATEPART ( YEAR , #rondedatum ) as varchar(4)) as JaarMaandNaamMedium
,Format(#rondedatum,'MMMM') + ' '+ Cast(DATEPART ( YEAR , #rondedatum ) as varchar(4)) as JaarMaandNaamLang
set #rondedatum = dateadd(day,1,#rondedatum)
--select cast(#rondedatum as date)
END
select 'Loop is klaar', getdate()
select 'Kalender Updaten (Feestdagen)', getdate()
update #kalender
set
werkdag = CASE WHEN DagVanMaand in (31) and maand = 12 THEN 0
WHEN DagVanMaand in (1) and maand = 1 THEN 0
WHEN DagVanMaand in (25,26) and maand = 12 THEN 0
WHEN DagVanMaand in (5) and maand = 5 AND Jaar < 2000 THEN 0
WHEN DagVanMaand in (5) and maand = 5 AND Jaar % 5 = 0 and jaar >= 2000 THEN 0
WHEN Jaar >= 2014 and dagvanMaand = 27 and maand = 4 THEN 0
WHEN Jaar >= 1898 and jaar <= 2013 and dagvanMaand = 30 and maand = 4 THEN 0
END,
feestdag = CASE WHEN DagVanMaand in (31) and maand = 12 THEN 'Oudjaar'
WHEN DagVanMaand in (1) and maand = 1 THEN 'Nieuwjaar'
WHEN DagVanMaand in (25,26) and maand = 12 THEN 'Kerst'
WHEN DagVanMaand in (5) and maand = 5 AND Jaar < 2000 THEN 'Bevrijdingsdag'
WHEN DagVanMaand in (5) and maand = 5 AND Jaar % 5 = 0 and jaar >= 2000 THEN 'Bevrijdingsdag'
WHEN Jaar >= 2014 and dagvanMaand = 27 and maand = 4 THEN 'Koningsdag'
WHEN Jaar >= 1898 and jaar <= 2013 and dagvanMaand = 30 and maand = 4 THEN 'Koninginnedag'
END
select 'Kalender Updaten (Werkdagen + werkdagtellers)', getdate()
--Werkdagteller runnen
declare #i as int = 0
declare #current_value int = 0
declare #werkdag as int
while #i < (select max(periodeid) from #kalender)
BEGIN
update #kalender
set werkdagteller =iif(werkdag = 0 , #current_value , #current_value + 1)
from #kalender
where PeriodeID = #i
set #werkdag = (select werkdag from #kalender where periodeid = #i)
set #current_value = iif(#werkdag = 0 , #current_value , #current_value + 1)
set #i = #i +1
set #print = cast(#i as varchar(max)) + ' van ' + cast((select max(periodeid) from #kalender) as varchar(max))
print #print
END
select 'Inserten in fysieke tabel', getdate()
IF OBJECT_ID (N'shared.dim_kalender', N'U') IS NOT NULL
BEGIN
drop table shared.dim_kalender
END
CREATE TABLE [shared].[dim_kalender](
[PeriodeID] [int] DEFAULT 0,
[Datum] [date] NOT NULL,
[DatumMedium] [nvarchar](25) DEFAULT '',
[DatumLang] [nvarchar](25) DEFAULT '',
[DatumExtraLang] [nvarchar](25) DEFAULT '',
[DatumVoluit] [nvarchar](50) DEFAULT '',
[DagVanJaar] [int] DEFAULT 0,
[DagVanWeek] [int] DEFAULT 0,
[DagVanMaand] [int] DEFAULT 0,
[DagNaamKort] [nvarchar](4000) DEFAULT '',
[DagNaamLang] [nvarchar](30) DEFAULT '',
[WerkDag] [int] DEFAULT 0,
[Weekend] [int] DEFAULT 0,
[Feestdag] [nvarchar](25) DEFAULT '',
[Werkdagteller] [int] DEFAULT 0,
[WeekNr] [int] DEFAULT 0,
[Iso_WeekNr] [int] DEFAULT 0,
[Maand] [int] DEFAULT 0,
[MaandNaamKort] [nvarchar](30) DEFAULT '',
[MaandNaamLang] [nvarchar](4000) DEFAULT '',
[Kwartaal] [int] DEFAULT 0,
[KwartaalNaamKort] [nvarchar](2) DEFAULT '',
[KwartaalNaamLang] [nvarchar](25) DEFAULT '',
[Jaar] [int] DEFAULT 0,
[JaarKwartaal] [int] DEFAULT 0,
[JaarKwartaalNaam] [nvarchar](7) DEFAULT '',
[JaarWeek] [int] DEFAULT 0,
[JaarWeekNaam] [nvarchar](25) DEFAULT '',
[Jaar_IsoWeek] [int] DEFAULT 0,
[Jaar_IsoWeekNaam] [nvarchar](25) DEFAULT '',
[JaarMaand] [int] DEFAULT 0,
[JaarMaandNaamKort] [nvarchar](25) DEFAULT '',
[JaarMaandNaamMedium] [nvarchar](25) DEFAULT '',
[JaarMaandNaamLang] [nvarchar](25) DEFAULT ''
) ON [PRIMARY]
INSERT INTO [shared].[dim_kalender]
select * from #kalender
No tsql on Redshift. No easy way to create a calendar table using Redshift. Redshift does not support any way to create rows on a table e.g. generate_series() is not supported
Very easy to create a calendar table elsewhere (e.g. excel or python) and upload to redshift.
Take a look here for a sample table that AWS provides
https://docs.aws.amazon.com/redshift/latest/gsg/rs-gsg-create-sample-db.html
Or you can search on stackoverflow and find a number of solutions.
My preferred approach is something like this:
First, create your table, (with diststyle all)
then..
insert into dwh.dim_date
select thisdate as date,
date_part(year,thisdate) as year,
date_part(mm,thisdate) as month,
to_char(thisdate, 'Mon') as month_name,
date_part(day,thisdate) as day_of_mon,
date_part(dow,thisdate) as day_of_week_num,
to_char(dat, 'thisdate') as day_of_week,
date_part(week,thisdate) as week_of_year,
date_part(doy,thisdate) as day_of_year,
decode(date_part(dow,thisdate),0,true,6,true,false) as is_weekend
from
(select
trunc(dateadd(day, ROW_NUMBER () over ()-1, '1960-01-01')) as thisdate
from YOUR_BIG_TABLE
);
where YOUR_BIG_TABLE is a table you have on redshift with a where clause to set the right number of future dates after year 1900

alternative way to TRIM for SSRS (not Crystal Reports)

I imported a report from Crystal to SSRS.
When I run the query in Microsoft Management Console, it throws errors unless I declare variables before the SELECT statement. When I run the query from Visual Studio, it bypasses these variables and only throws an error on the TRIM function.
From what I can tell a JOIN statement may be used instead of a TRIM, but I am not sure.
This is the portion of a where clause that I am trying to change/adapt to work with SSRS, which is throwing an error -- any suggestions appreciated.
Also, I am having issues with the DateSerial in the WHERE clause as follows:
AND (CAST(#StartDate AS Date) <> DateSerial(1900, 01, 01)) AND
Trim does not work in SQL only in the report expressions you would have to use LTrim and RTrim to make this work.
AND ( ( NOT ( #Status IS NULL )
AND RTrim(LTrim(#Status)) <> 'All' )
(( ( RTrim(Ltrim(#Status)) = 'Completed' )
AND RTrim(LTrim(#AssignedTo)) <> 'All' )
AND ( submission.assignedto IN ( #AssignedTo ) )
INCLUDING THE ENTIRE WHERE CLAUSE:
WHERE ( #ParameterIds IS NOT NULL or ParameterIds = #ParameterIds )
AND #ParameterIds <> 0 )
AND ( requested_table.parameterid IN ( #ParameterIds ) ) )
AND requested_table.columnname = 'INSERT'
AND ( ( NOT ( #Parameter2 IS NULL )
AND Trim(#Parameter2) <> 'All' )
AND (( ( Trim(#Parameter2) = 'Completed' )
AND (( requested_table.columnname = 'Dup'
OR requested_table.columnname = 'IDup'
OR requested_table.columnname = 'W/D'
OR requested_table.columnname = 'Done'
OR requested_table.columnname = 'QA Review Dup'
OR requested_table.columnname = 'X' ))
OR ( requested_table.columnname IN ( #Parameter2 ) ) )) )
AND ( ( #ParameterIds = 0 )
AND ( ( ( NOT ( #StartDate IS NULL )
AND ( Cast (#StartDate AS DATE) <>
Dateserial(1900, 01, 01) ) )
AND ( submission.dateimported >= Datevalue (#StartDate) ) )
AND ( ( NOT ( #EndDate IS NULL )
AND ( Cast (#EndDate AS DATE) <>
Dateserial(1900, 01, 01) )
)
AND ( table.dateimported <= Datevalue (#EndDate) )
) ) )
AND ( ( #ParameterIds = 0 )
AND (( ( NOT ( #Parameter5 IS NULL )
AND Trim(#Parameter5) <> 'All' )
AND ( table.assignedto IN ( #Parameter5 ) ) )) )
Fix the Dateserial and this should work.
WHERE ( #ParameterIds IS NOT NULL or ParameterIds = #ParameterIds )
AND (#ParameterIds <> 0 )
AND ( requested_table.parameterid IN ( #ParameterIds ) )
AND requested_table.columnname = 'INSERT'
AND ( ( (#Parameter2 IS NOT NULL )
AND LTRIM(RTrim(#Parameter2)) <> 'All' )
AND (( ( LTRIM(RTrim((#Parameter2)) = 'Completed' )
AND (( requested_table.columnname = 'Dup'
OR requested_table.columnname = 'IDup'
OR requested_table.columnname = 'W/D'
OR requested_table.columnname = 'Done'
OR requested_table.columnname = 'QA Review Dup'
OR requested_table.columnname = 'X' ))
OR ( requested_table.columnname IN ( #Parameter2 ) ) )) )
AND ( ( #ParameterIds = 0 )
AND ( ( ( ( #StartDate IS NOT NULL )
AND ( Cast (#StartDate AS DATE) <>
Dateserial(1900, 01, 01) ) )
AND ( submission.dateimported >= (#StartDate) ) )
AND ( ( ( #EndDate IS NOT NULL )
AND ( Cast (#EndDate AS DATE) <>
Dateserial(1900, 01, 01) )
)
AND ( table.dateimported <= (#EndDate) )
) ) )
AND ( ( #ParameterIds = 0 )
AND (( ( ( #Parameter5 IS NOT NULL )
AND RTRIM(LTrim(#Parameter5)) <> 'All' )
AND ( table.assignedto IN ( #Parameter5 ) ) )) )

Sql Server 2008 R2 Query Optimization

I have a Sql Ad-hoc query which is performing badly. Please help me or give me some suggestions to optimize it. Here is the query below:
SELECT TOP 20 CustomerPrimaryExtID,
Max(POSTimeStamp) AS TransactionDate,
ExtLocationCode,
0 AS RedemptionAmount,
0 AS RedemptionCount,
TerminalNum,
LogixTransNum,
POSTransNum AS TransNum,
0 AS DetailRecords,
CustomerTypeID,
PresentedCustomerID,
PresentedCardTypeID,
HHID,
Replayed,
0 AS TransContext,
isnull(TransTotal, 0) AS TransTotal
FROM TransHist AS TH WITH(nolock)
WHERE ( ( ( CustomerPrimaryExtID IN ( '' )
AND HHID IS NULL )
OR HHID = '0000000250000013408'
AND CustomerTypeID <> 1 )
OR ( CustomerPrimaryExtID = '0000000250000013408'
AND CustomerTypeID = 1 ) )
AND NOT EXISTS (SELECT LogixTransNum
FROM TransRedemptionView AS TR2
WHERE ( ( ( CustomerPrimaryExtID IN ( '' )
AND HHID IS NULL )
OR HHID = '0000000250000013408'
AND CustomerTypeID <> 1 )
OR ( CustomerPrimaryExtID = '0000000250000013408'
AND CustomerTypeID = 1 ) )
AND TH.LogixTransNum = TR2.LogixTransNum)
GROUP BY CustomerPrimaryExtID,
HHID,
CustomerTypeID,
PresentedCustomerID,
PresentedCardTypeID,
LogixTransNum,
POSTransNum,
TerminalNum,
ExtLocationCode,
Replayed,
TransTotal
ORDER BY TransactionDate DESC
Given the 62% cost on TransRedemption I would think an index on CustomerPrimaryExtID, HHID, CustomerTypeID and LogixTransNum would help that some.
You could also look at doing:
FROM
TransHist TH
LEFT OUTER JOIN
TransRedemption TR2
ON TH.LogixTransNum = TR2.LogixTransNum
Don't use the view in the sub query or the join unless something is being done in that view to limit the number of rows returned from TransRedemption.
Then remove:
AND NOT EXISTS (SELECT LogixTransNum
FROM TransRedemptionView AS TR2
WHERE ( ( ( CustomerPrimaryExtID IN ( '' )
AND HHID IS NULL )
OR HHID = '0000000250000013408'
AND CustomerTypeID <> 1 )
OR ( CustomerPrimaryExtID = '0000000250000013408'
AND CustomerTypeID = 1 ) )
AND TH.LogixTransNum = TR2.LogixTransNum)
from the where clause and replace with
AND TR2.LogixTransNum IS NULL
If TransRedemption has a lot of columns then you may want to limit the results in the join like so:
FROM
TransHist TH
LEFT OUTER JOIN
(
SELECT
LogixTransNum
FROM
TransRedemption
) TR2
ON TH.LogixTransNum = TR2.LogixTransNum

TSQL dbo.split including a key

So I have the function below. My question is how can I get the following query to use the function to to create a view. I'm trying to get p_c_id to be the #ValueID and notes to be the #List.
select p_c_id, notes from dbo.product
create FUNCTION [dbo].[Split2Value]
( #Delimiter varchar(5),
#List varchar(8000),
#ValueID bigint
)
RETURNS #TableOfValues table
( RowID smallint IDENTITY(1,1),
[Value] varchar(500),
ValueID bigint
)
AS
BEGIN
DECLARE #LenString int
WHILE len( #List ) > 0
BEGIN
SELECT #LenString =
(CASE charindex( #Delimiter, #List )
WHEN 0 THEN len( #List )
ELSE ( charindex( #Delimiter, #List ) -1 )
END
)
INSERT INTO #TableOfValues
SELECT substring( #List, 1, #LenString ), #ValueID
SELECT #List =
(CASE ( len( #List ) - #LenString )
WHEN 0 THEN ''
ELSE right( #List, len( #List ) - #LenString - 1 )
END
)
END
RETURN
END
select
SV.RowID,
SV.[Value],
ValueID
from dbo.product as P
cross apply dbo.Split2Value('DELI?', P.notes, P.p_c_id) as SV