PowerShell SQL Tutorial Part 2 : Manipulating Data

preview_player
Показать описание
Learn how to iterate through the data we get from the database and be able to execute if statements on them and display them, export them etc. In this video I go over how to take the data we got from the select statement and put it in a format where we can use foreach loops to iterate through the rows and perform actions on the data.

Tags:
Sql server, powershell, fetching data, powershell sql, powershell data science, automation, jacked programmer, scripting, coding, programming
Рекомендации по теме
Комментарии
Автор

High value content. Most underrated Programming coach on the interwebs imho, right now! Happy I found him that early. Here you go algorithm, a long comment!

fpost
Автор

Thanks for the video.
My understanding is that DataSet is useful for obtaining multiple tables from a database, for working with the relationships between those tables. Since in this case we want only one table, it's considered more efficient to use DataTable instead of DataSet. That should allow you to eliminate Line 14 from your script but the rest should otherwise remain very similar.
Secondly I believe there's no need to statically open or close the connection when using DataAdapter. DataAdapter will do that dynamically as needed.

tdoan
Автор

Thank you for the video and the scenario of how to use it.

create database Logging
use Logging
create table Log(
id bigint identity,
occuredAt datetime default CURRENT_TIMESTAMP,
appName nvarchar(100),
computerName nvarchar(255),
details text,
);

insert into Log (appName, computerName, details) values ('Test', 'TestComputer', 'TestDetails')
insert into Log (appName, computerName, details) values ('Test', 'TestComputer', 'TestDetails')
insert into Log (appName, computerName, details) values ('Prod', 'TestComputer2', 'TestDetails')
insert into Log (appName, computerName, details) values ('Prod', 'TestComputer', 'TestDetails')
insert into Log (appName, computerName, details) values ('Test', 'TestComputer2', 'TestDetails')

alexyou
Автор

you didn't provide the inserts in the description :/

TheDogtag
Автор

Why so complicated? What are you doing here? foreach($row in $data){
get-date -date $row.occuredAt -Format yyy-MM-dd
}
why the get-date. couldn't you just foreach $row.occuredAt ?

fpost